问题描述
有一个 @WebServlet(urlPatterns = "/myServlet/")
.如果用户转到 myapp/myServlet/other
,我仍然希望我的 servlet 被捕获.可以这么说,在 servlet 路径之后通配任何内容.我怎么能这样做?
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?
推荐答案
您可以使用 *
作为前缀或后缀通配符.在您的情况下,您可以使用 /myServlet/*
进行文件夹映射.
You can use *
as prefix or suffix wildcard. In your case, you can use /myServlet/*
for a folder mapping.
@WebServlet("/myServlet/*")
路径信息(URL 中映射后的部分)在 servlet 中可用的方式如下:
The path info (the part after the mapping in the URL) is in the servlet by the way available as:
String pathInfo = request.getPathInfo();
这会在 myapp/myServlet/other
的情况下返回 /other
.
This would in case of myapp/myServlet/other
return /other
.
这篇关于servlet 的通配符路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!