servlet的通配符路径?

tcbh2hod  于 2021-07-12  发布在  Java
关注(0)|答案(2)|浏览(368)

有一个 @WebServlet(urlPatterns = "/myServlet/") . 如果用户转到 myapp/myServlet/other ,我仍然希望我的servlet能够捕获。也就是说,在servlet路径之后使用通配符。我怎么能这么做?

ecfsfe2w

ecfsfe2w1#

你可以用 * 作为前缀或后缀通配符。在你的情况下,你可以使用 /myServlet/* 用于文件夹Map。

@WebServlet("/myServlet/*")

路径信息(url中Map之后的部分)在servlet中的方式如下:

String pathInfo = request.getPathInfo();

这将是在 myapp/myServlet/other 返回 /other .

另请参见:

servlet和路径参数,如/xyz/{value}/test,如何在web.xml中Map?

pcrecxhr

pcrecxhr2#

使用“/myservlet/*”作为servletMap。

相关问题