header

Torsten Curdt’s weblog

HttpServletRequest Examples

What was the semantic of the servlet request parameter again? I can’t remember how often I wrote code that produced something along the lines of the following.

The direct servlet mapping:

GET http://localhost:8080/statement
contextPath:
pathInfo:null
pathTranslated:null
requestUri:/statement
servletPath:/statement
queryString:null

With trailing slash:

GET http://localhost:8080/statement/
contextPath:
pathInfo:/
pathTranslated:/path/to/webapp
requestUri:/statement/
servletPath:/statement
queryString:null

With path component:

GET http://localhost:8080/statement/test
contextPath:
pathInfo:/test
pathTranslated:/path/to/webapp/test
requestUri:/statement/test
servletPath:/statement
queryString:null

With query string:

GET http://localhost:8080/statement/test?as=true
contextPath:
pathInfo:/test
pathTranslated:/path/to/webapp/test
requestUri:/statement/test
servletPath:/statement
queryString:as=true

Just for the records.

  • Thanks! Whenever I find myself having to use HttpServletRequest I can never remember all the damn properties :) Now bookmarked for future use - thank you!
  • good idea, this post!
blog comments powered by Disqus