Wildcard path for servlet?

The presence of @WebServlet(urlPatterns = "/myServlet/") . If the user goes to myapp/myServlet/other , I still want my servlet to catch. So to speak, wildcard something along the path of the servlet. How can i do this?

+6
source share
2 answers

You can use * as a prefix or suffix. In your case, you can use /myServlet/* to map folders.

 @WebServlet("/myServlet/*") 

The path information (the part after matching in the URL) is in the servlet, available as:

 String pathInfo = request.getPathInfo(); 

This would be the case with myapp/myServlet/other return /other .

See also:

+20
source

use "/ myServlet / *" as the servlet mapping.

0
source

Source: https://habr.com/ru/post/928105/


All Articles