Extra path information in HttpServletRequest ???


Web tier: servlets, JSP, Web frameworks: Extra path information in HttpServletRequest ???

  1. Extra path information in HttpServletRequest ??? (6 messages)

    What is the extra path information in HttpServletRequest? I mean, where does it from, what kind of information it contains, and how is it initially set?

    Thank you.

    Di He
  2. Are you referring to information returned from HttpServletRequest.getPathInfo()? According to the JavaDocs:

    Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string. This method returns null if there was no extra path information.

    INO, if you have a servlet registered to the path "/MyServlet", and you access your servlet with "http://blah.blah:port/MyServlet/extra/path/info?query=string". All of the information in HttpServletRequest comes from your servlet container. When a request comes in, the servlet container creates the request object and populates it with information coming from the HTTP request.

  3. Thank you, Andy. But, where are the /extra/path/info from? By my understanding, it is from HTML. If it is, where and how it is setted?

  4. The extra path info comes from the URL that is used to access your servlet. The URL can come from the user typing it directly into the location/address box in the browser, or it can come from a link in an HTML page. If you're building an application, the URL will probably come from an HTML page via an href or form action.

    e.g. href="MyServlet/extra/path/info"
    <form name="blah" action="MyServlet/extra/path/info">

    Of course, you can make the extra path info dynamic using a JSP page or servlet to generate the HTML document.

  5. Thanks, Andy. I think I got it.

  6. Andy, can you me what kind of information, usually, should be put into the extra/path/infor part?


  7. I really haven't seen many uses of extra path info. One use that I've seen is in some of the default servlets that come with a servlet engine. Most servlet engines come with a servlet servlet (or invoker servlet). The servlet servlet allows you to run a servlet by it's fully-qualified class name.

    For example,

    The servlet servlet is registered to handle "/servlet" URLs. The information that comes after ("/com.mycompany.TestServlet") is extra path info. Everything after the "?" is the query string. The extra path info tells the serlvet servlet which servlet to load and invoke.

    The file servlet in most servlet engines works the same way.

    If you wanted to build an application with a front/dispatch servlet, you could do something similar.