根据查询字符串更改 URL [JSP/Servlet]
如果问题措辞不好,我深表歉意......我不太确定如何去问。
我将如何根据查询字符串更改 URL,例如:
如果有人单击一些可爱的胡萝卜的链接,则 URL 不是 foo.com/product.jsp?id=2,而是 foo.com/产品/一些可爱的胡萝卜。
我尝试将映射添加到 web.xml,但我认为我没有采取正确的方法。
任何帮助将不胜感激。
I apologise if the question is poorly worded... I wasn't quite sure how to go about asking.
How would I go about changing the URL depending on the query string, for example:
If someone clicks a link for some lovely carrots, instead of the URL being foo.com/product.jsp?id=2 it would be foo.com/product/some-lovely-carrots.
I tried adding mapping to web.xml, but I don't think I'm going the right way about it.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这称为“漂亮 URL”或“友好 URL”。基本上,您需要创建一个过滤器或者一个前端控制器 servlet 来完成这项工作。假设您选择过滤器方向,它看起来如下所示:
将此过滤器映射到
/*
的 URL 模式上,并按如下方式更改链接This is called "pretty URL" or "friendly URL". Basically, you'd need to create a filter or maybe a front controller servlet to achieve the job. Assuming that you go the filter direction, it would look something like as following:
Map this filter on an URL pattern of
/*
and change the link as follows