This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
request.getPathInfo() - becomes null when I don't use wildcards in the url pattern.
request.getServletPath() - becomes empty when you use a url pattern name of a servlet like - '/index.jsp' or '/*'.
but will have a name if it is written like this - '/anyServletName/index.jsp' or '/anyServletName/*'.
it will output - '/anyServletName'.
Joined: Oct 21, 2008
From the javadoc
getServletPath : Returns the part of the request's URL that calls the servlet. This includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string.
That's why getServletPath() for '/index.jsp' or '/*' returns null, that's because these urls do not call explicitly the servlet.
On the other hand '/anyServletName/index.jsp' or '/anyServletName/* call explicitly your servlet that's why getServletPath() returns something