Wildcard path for servlet?

2019-01-14 13:54发布

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?

2条回答
迷人小祖宗
2楼-- · 2019-01-14 14:18

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:

查看更多
Evening l夕情丶
3楼-- · 2019-01-14 14:22

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

查看更多
登录 后发表回答