apache 如何在 Tomcat 6 中重写 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1563799/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:16:03  来源:igfitidea点击:

How to rewrite URL in Tomcat 6

apachetomcatservletsstruts2

提问by Enrique

I'll build a web application and I want to use url rewriting. In apache this is done with mod_rewrite. But how can I rewrite urls with Tomcat 6?

我将构建一个 Web 应用程序,并且我想使用 url 重写。在 apache 中,这是通过 mod_rewrite 完成的。但是如何使用 Tomcat 6 重写 url?

I want to use Struts 2 framework.

我想使用 Struts 2 框架。

回答by Jonathan Feinberg

I've used UrlRewriteFilteras a critical component of a couple of my tomcat-based apps, and have been totally happy with it.

我已经使用UrlRewriteFilter作为我的几个基于 tomcat 的应用程序的关键组件,并且对它非常满意。

回答by Droo

You can do wildcard mappingsin your struts.xml:

您可以在 struts.xml 中进行通配符映射

<action name="*Crud" class="example.Crud" method="{1}">
...

Then I think you can set your default action extension to / in struts.properties:

然后我想你可以在struts.properties中将你的默认操作扩展设置为 / :

struts.action.extension=/

As for the URL filter, here's a good blog post.

至于 URL 过滤器,这里有一篇很好的博客文章

回答by fglez

It could bea good idea to have Apache as a web server for static content in front of Tomcat application server.

可以让Apache作为在Tomcat应用服务器的前面静态内容的Web服务器是一个好主意。

You can then use Apache's mod_rewrite and Tomcat.

然后您可以使用Apache 的 mod_rewrite 和 Tomcat

In any case, there's a similar question.

无论如何,有一个类似的问题