Suppose I have a Java servlet that I want to use for two (or more) different url-patterns:
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/this/exact/path</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/that/prefix/path/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/yet/another/exact/path</url-pattern>
</servlet-mapping>
MyServlet will be called for any of:
/this/exact/path
/yet/another/exact/path
/that/prefix/path/param1
/that/prefix/path/param2.html
what I want to know is how can I tell from inside my code what was the path for which the request was matched for . (i.e. if the request was made to /myapp/yet/another/exact/path i want to get the string /yet/another/exact/path).
I guess also that there should be a way to differentiate between the /that/prefix/path/ and what ever was matched with the * It would be nice if someone could tell me how this should be done.
I tried String path = req.getRequestURI() but it also returns the /myapp part.
HttpServletRequest.getServletPath()returns the URL pattern excluding/*, andHttpServletRequest.getPathInfo()returns the part matched by/*(ornullfor exact match).