是否有适用于 Tomcat/Java 的 url 重写引擎?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/950497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a url rewriting engine for Tomcat/Java?
提问by
How can we provide URL-Rewriting support for Tomcat/Java ?
我们如何为 Tomcat/Java 提供 URL 重写支持?
mod_rewriteprovides this functionality for Apache and can modify URLs even before they reach the handler (e.g. PHP). Is there a similar tool in Java/Tomcat ?
mod_rewrite为Apache 提供了此功能,甚至可以在URL 到达处理程序(例如PHP)之前修改它们。Java/Tomcat 中是否有类似的工具?
To be more specific we need modifications such as
更具体地说,我们需要修改,例如
http://www.somedomain.com/person/1
Maps to
http://www.somedomain.com/details?personId=1
And this should be transparent to the servlet code, i.e. we should be able to access request.getParameter("personId")in the servlet and get the personId (1 in this case).
这对servlet 代码应该是透明的,即我们应该能够request.getParameter("personId")在servlet 中访问并获得personId(在这种情况下为1)。
Did you come across such a scenario ? What tool did you use ?
Would love to hear your suggestions.
你遇到过这样的场景吗?你用的是什么工具?
很想听听您的建议。
回答by Robert Munteanu
See the URLRewriteFilter
回答by lobster1234
I did run into this scenario but went with front-ending my Tomcat with Apache+mod_rewrite, to keep it simple. Besides there are other advantages of front-ending with Apache HTTPd depending on your use case.
我确实遇到过这种情况,但是为了保持简单,我使用 Apache+mod_rewrite 前端我的 Tomcat。此外,根据您的用例,使用 Apache HTTPd 进行前端还有其他优势。

