• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javax.servlet.forward.path_info

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  •  
    Christophe Verré
    Sheriff
    Posts: 14691
    16
    Eclipse IDE VI Editor Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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"
     
    Ranch Hand
    Posts: 368
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Christophe,
    For such a nice information.
     
    Ranch Hand
    Posts: 437
    Oracle Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 14691
    16
    Eclipse IDE VI Editor Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 437
    Oracle Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thankyou.
     
    Leonard Fischer
    Ranch Hand
    Posts: 47
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Christopher, many thanks.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic