Having an @WebServlet(urlPatterns = "/myServlet/"). If the user goes to myapp/myServlet/other, I still want my servlet to catch. So to say, wildcard anything on after the servlet path. How could I do this?
Asked
Active
Viewed 9,138 times
10
BalusC
- 1,040,783
- 362
- 3,548
- 3,513
membersound
- 74,158
- 163
- 522
- 986
2 Answers
32
You can use * as prefix or suffix wildcard. In your case, you can use /myServlet/* for a folder mapping.
@WebServlet("/myServlet/*")
The path info (the part after the mapping in the URL) is in the servlet by the way available as:
String pathInfo = request.getPathInfo();
This would in case of myapp/myServlet/other return /other.
See also:
-
2Wow thats incredibly nice! I just tried the * wildcard with urlPatterns, which did not work. But this does as expected. – membersound Oct 19 '12 at 11:11
-
3By the way you just answered my next question (how to get the path) :) – membersound Oct 19 '12 at 11:12