HttpServletRequest Demystified

April 17, 2009

Today is about the tenth time I’ve needed to redirect to a slightly modified version of the current URL. So, I have to piece together a URL from pieces in an HttpServletRequest. And I can never remember which piece is which. I know, I know, the difference between “servletPath” and “pathInfo” should be intuitively obvious to me. So now, for the last time, here is what the pieces mean, for an example URL:

  • protocol – “HTTP/1.1” (you’ll have to convert this back to http or https, for example)
  • serverName – “”
  • serverPort – 8080
  • contextPath – “/appname”
  • servletPath – “/servletname”
  • pathInfo – “/my/path”
  • queryString – “name=value”

Not looking at all of these values now, so some might be slightly off – please post a comment to correct me.