10

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
membersound
  • 81,582
  • 193
  • 585
  • 1,120

2 Answers2

33

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

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

Sumit Desai
  • 1,542
  • 9
  • 22