java 除了一个 servlet 之外,过滤器映射到 Struts2 的所有内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3843548/
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
Filter mapping for everything to Struts2 besides one servlet?
提问by Andy
I have a Struts2 (2.1.8.1) web application. My web.xml looks like,
我有一个 Struts2 (2.1.8.1) Web 应用程序。我的 web.xml 看起来像,
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
This is configured to map all requests to the struts filter. I want to add a servlet in my web application. I want to send all requests with a certain url pattern to that servlet. I want everything else to go to my struts servlet.
这被配置为将所有请求映射到 struts 过滤器。我想在我的 Web 应用程序中添加一个 servlet。我想将具有特定 url 模式的所有请求发送到该 servlet。我希望其他所有内容都转到我的 struts servlet。
I know I could only map "*.action" to the struts servlet, but I hate .action being on the end of all my URL's.
我知道我只能将“*.action”映射到 struts servlet,但我讨厌 .action 位于所有 URL 的末尾。
回答by Matt
In your struts.xml add:
在你的 struts.xml 添加:
<constant name="struts.action.excludePattern" value="/ServletToExcludeFromStruts*"/>
The value be comma delimited as well for multiple exclusions. See http://struts.apache.org/2.2.1/docs/webxml.html
对于多个排除项,该值也以逗号分隔。见http://struts.apache.org/2.2.1/docs/webxml.html