拥有一个@WebServlet(urlPatterns = "/myServlet/")
。如果用户去myapp/myServlet/other
,我仍然希望我的 servlet 能够捕获。也就是说,在 servlet 路径之后使用通配符。我怎么能这样做呢?
您可以使用*
作为前缀或后缀通配符。在你的情况下,你可以使用/myServlet/*
用于文件夹映射。
@WebServlet("/myServlet/*")
路径信息(URL 中映射之后的部分)位于 servlet 中,如下所示:
String pathInfo = request.getPathInfo();
这会在以下情况下myapp/myServlet/other
return /other
.
也可以看看:
- Servlet和路径参数如/xyz/{value}/test,如何在web.xml中映射? https://stackoverflow.com/questions/8715474/servlet-and-path-parameters-like-xyz-value-test-how-to-map-in-web-xml/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)