I am building a site with JSPs and Servlets.
How do I map a URL like this example.com/12345 so that I get the response as if the request was example.com/content.jsp?id=12345?
I am building a site with JSPs and Servlets. How do I map a
Share
Use an
url-patternof/*, gather the pathinfo byHttpServletRequest#getPathInfo()and finally forward the request to the desired destination byRequestDispatcher#forward().Basic kickoff example (business logic and exception handling aside):
Alternatively, especially if actually no business logic is involved, you can also use the Tuckey’s UrlRewriteFilter for this. This way you can rewrite your URL’s the way as you would do with Apache HTTPD’s well known
mod_rewrite.