URL Embedded page name#

"URL embedding" of a parameter means insertign the param as part of the url, rather than as a standard parameter. In the case of JSPWiki, that would mean, for instance, instead of -

http://www.mywiki.com/Wiki.jsp?page=MyPage
you would have:
http://www.mywiki.com/Wiki.jsp/page/MyPage

and instead of

http://www.mywiki.com//attach?page=Coin%2Fcoin.png
you would have:
http://www.mywiki.com//attach/page/Coin/coin.png

Why is this good? well, several reasons:

  • You have a nicer URL to link to
  • You can define the mime-type for attachments properly, so that the browser will launch the right application for them.
  • You can difrentiate access rights to Wiki pages

A couple of points:

  • Nicer URLs, yes. But the best way to do this currently is to probably use mod_rewrite in Apache.
    (YM): assuming you're running under apache. We use Tomcat as the web server. We should be migrating to a serious setup in a month or two.
  • This does not affect MIME-types. The Content-Type header is set by server using the standard ServletContext API, so if you're getting the wrong mime-type, then you should check your server configuration. Yes, I know, some Windows programs (InternetExplorer?) want to override whatever the server offers by checking the file extension themselves. But they are in error. // (YM): Again, this may be a tomcat issue. When I link directly to the file, I get the correct mime-type. when I let the attach servlet do it for me, I get an unknown type. IE? don't insult me! :)
  • That is only true if you are using URL-based filtering combined with basic authentication of the servlet container. I would of recommend against it - it will be a real hassle to manage.
    (YM) then what is your recommendation? It is a hassle, and we should eventualy migrate to something better, but we wanted a Q&D solution..

--JanneJalkanen

I've moved the discussion on attach servlet mime-type problem out of this page.


Here's a piece of undebugged code for doing this.

Of course, it requires proper url-mapping in your web.xml..


public class AttachmentServlet
{
:
    public void doGet( HttpServletRequest  req, HttpServletResponse res ) 
        throws IOException, ServletException 
    {
        String page     = m_engine.safeGetParameter( req, "page" );
- - - - - - - - - - - - - - change to ->
    public void doGet( HttpServletRequest  req, HttpServletResponse res ) 
        throws IOException, ServletException 
    {
        String page     = getPage(req);
		

	/**
	 * Get the page name.
	 * <ul>
	 *    <li>Get the "page" parameter from the request.</li>
	 *    <li>If null, check for url embedding, i.e. http://.../page/WikiPage/attacment.whatever</li>
	 * 	  <li>If null, return DEFAULT_PAGE</li>
	 * </ul>
	 * this method is public so that it can be used by Wiki.jsp, Edit.jsp, etc.
	 */
	 public String getPage(HttpServletRequest  req) {
		String name = m_engine.safeGetParameter(req, HDR_NAME);
		
		if (null == name) {
		   // try url embedded name.
		   String url = request.getRequestURL().toString();
		   String marker = "/"+HDR_NAME+"/";
		   int i = url.indexOf(marker);
		   if (i > 0) {
		   	  name = url.subString(i+marker.length());
		   }
		}
		
		if (name == null) name = DEFAULT_NAME;
		
		return name;
	}	

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-10) was last changed on 21-May-2003 13:16 by YishayMor