0
votes

I have seen this answer

but it does not help my case.

I have a class that implements an HttpServlet. Now I want to place a URL inside it so that it has the following pattern: resource/identifier/resource.

For example, I want to make this REST call: http://example.com/owners/1234/dogs

I tried to place a URL like this in the servlet: http://example.com/owners/*/dogs, but the call never reached the servlet and was not handled.

1

1 Answers

3
votes

If I understood well you want your servlet to be mapped to something like /owners/*/dogs.

Well, unfortunately Servlets can only use wildcards at the beginning or end of the mapping. So you would have to map it to /owners/* and then using request.getPathInfo() parse the rest of the url to extract the path info.

Your best options are to use the standard JAXRS or Spring MVC, both of which support path variables.