如何访问 servlet 的 web.xml 文件的第二个参数?
假设在我的 web.xml 文件中,我定义了一个 servlet,如下所示:
<url-pattern>/MyURL/*</url-pattern>
How do i access everything pass in the * in my servlet?我打算将此方案用于漂亮的 URL。
Say in my web.xml file, I define a servlet like so:
<url-pattern>/MyURL/*</url-pattern>
How do i access anything passed in the * in my servlet? I'm planning to use use this scheme for pretty(-ish) URLs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HttpServletRequest#getPathInfo()
正是用于此目的。就这样。无需按照此处另一个答案中的建议从中提取 servlet 路径的子串。另请参阅我对您的其他问题的回答。
The
HttpServletRequest#getPathInfo()
is exactly for this purpose.That's all. No need to substring the servlet path from it as suggested in another answer here. Also see my answer on your other question.
在 HttpServlet 的 doGet 或 doPost 方法中,您可以使用 getRequestURI HttpServletRequest 对象来检索 URL 的路径部分。因为听起来您还想砍掉映射到 servlet 的路径部分,可以使用 getServletPath 方法,然后执行如下操作:
In the HttpServlet's doGet or doPost method you can use the getRequestURI method of the HttpServletRequest object to retrieve the path part of the URL. Since it sounds like you also want to chop off the part of the path that mapped to the serlvet could use the getServletPath method and then do something like this: