File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes javax.servlet.forward.path_info Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "javax.servlet.forward.path_info" Watch "javax.servlet.forward.path_info" New topic
Author

javax.servlet.forward.path_info

Leonard Fischer
Ranch Hand

Joined: Apr 17, 2009
Posts: 47
Hello Everyone. Can anyone give me an example which results in a non-null value for the request attribute: javax.servlet.forward.path_info?

I've been able to get values for the other four request attributes: javax.servlet.forward.request_uri, javax.servlet.forward.context_path, javax.servlet.forward.servlet_path, and javax.servlet.forward.query_string. I forward to a page with the following code:


In the destination page, I display the request attributes as follows:



So this is fine, but no matter how I change the mappings in web.xml, and no matter what parameters I pass (in the browser address bar, or in the <jsp:forward>) I always end up with a null value for javax.servlet.forward.path_info.

I'd appreciate any help in getting a non-null value for javax.servlet.forward.path_info. Many thanks!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The reason is explained in the Servlets Specification, SRV.4.4 Request Path Elements.

-----------------------------
  • Context Path: The path prefix associated with the ServletContext that this servlet is a part of. If this context is the “default” context rooted at the base of the Web server’s URL name space, this path will be an empty string. Otherwise, if the context is not rooted at the root of the server’s name space, the path starts with a’/’ character but does not end with a’/’ character.
  • Servlet Path: The path section that directly corresponds to the mapping which activated this request. This path starts with a’/’ character except in the case where the request is matched with the ‘/*’ pattern, in which case it is an empty string.
  • PathInfo: The part of the request path that is not part of the Context Path or the Servlet Path. It is either null if there is no extra path, or is a string with a leading ‘/’.


  • The following methods exist in the HttpServletRequest interface to access
    this information:
  • getContextPath
  • getServletPath
  • getPathInfo


  • It is important to note that, except for URL encoding differences between the
    request URI and the path parts, the following equation is always true:

    requestURI = contextPath + servletPath + pathInfo
    -----------------------------

    There's an example which shows that for a request like "/catalog/help/feedback.jsp", the following values are returned :
  • ContextPath: /catalog
  • ServletPath: /help/feedback.jsp
  • PathInfo: null


  • [My Blog]
    All roads lead to JavaRanch
    Christophe Verré
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14687
        
      16

    You can try to get a PathInfo by appending an extra path to the servlet's path. Try this :

    Forward.java

    web.xml


    Now try to access the servlet via something like "http://localhost:8080/test/ForwardTest/hiLeonard"
    Shailesh Narkhede
    Ranch Hand

    Joined: Jul 10, 2008
    Posts: 368
    Thanks Christophe,
    For such a nice information.


    Thanks,
    Shailesh
    Chinmaya Chowdary
    Ranch Hand

    Joined: Apr 21, 2008
    Posts: 432
    Hi Christophe. I tried this example with little modification
    I got output as
    name:.....>org.apache.catalina.jsp_classpath,..... value:......> null

    name:.....>org.apache.catalina.WELCOME_FILES,..... value:......> null

    name:.....>javax.servlet.context.tempdir,..... value:......> null

    name:.....>org.apache.catalina.resources,..... value:......> null


    Can you please explain, what are org.apache.catalina.jsp_classpath, org.apace.catalina.WELCOME_FILES, javax.servlet.context.tempdir, org.apache.catalina.resources? Thankyou.
    Christophe Verré
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14687
        
      16

    Can you please explain, what are org.apache.catalina.jsp_classpath, org.apace.catalina.WELCOME_FILES, javax.servlet.context.tempdir, org.apache.catalina.resources? Thankyou.

    These are attributes set by Tomcat. Consult the documentation if you want to know what they are used for.
    Chinmaya Chowdary
    Ranch Hand

    Joined: Apr 21, 2008
    Posts: 432
    Thankyou.
    Leonard Fischer
    Ranch Hand

    Joined: Apr 17, 2009
    Posts: 47
    Christopher, many thanks.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: javax.servlet.forward.path_info