Does servlet support urls as follows:
/xyz/{value}/test
where value could be replaced by text or number.
How to map that in the web.xml?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your best bet is the URL pattern
/xyz/*.The Servlet API doesn’t support to have the URL pattern wildcard
*in the middle of the mapping such as/xyz/*/testnor URI templates. It only allows the wildcard*in the end of the mapping like so/prefix/*or in the start of the mapping like so*.suffix.You can extract the path information using
HttpServletRequest#getPathInfo(). Here’s a basic kickoff example how to extract the path information, null and array index out of bounds checks omitted for brevity:If you want to be able to use URI templates nonetheless, and this is actually intended to be a REST endpoint rather than a HTML page, then take a look at Jakarta REST (JAX-RS):
If you want more finer grained control liks as possible with Apache HTTPD’s
mod_rewrite, then you could look at Tuckey’s URL rewrite filter or homegrow your own URL rewrite filter.