情况:在web.xml中配置一个servlet映射路径为/test,但是struts2的filermapping为/*.
这样,servlet就不会被映射到。
解决:
<constant name="struts.action.excludePattern" value="/YourServlet"/>
参考:
Why the Filter is mapped with /* and how to configure explicit exclusions (since 2.1.7)
In the example above we've mapped the Struts 2 dispatcher to /*, so Struts 2 has a crack at all incoming requests. This is because Struts 2 serves static content from its jar files, including Dojo JavaScript files (if using S2.0, or the Dojo plugin in S2.1+) and FreeMarker templates for the Struts 2 tags that produce HTML.
If we change the filter mapping to something else, for example /*.html, we must take this in to account and extract the content that would normally be served from the Struts 2 jar files, or some other solution.
Since Struts 2.1.7, you are able to provide a comma seperated list of patterns for which when matching against the
request URL the Filter will just pass by. This is done via the configuration option struts.action.excludePattern, for example in your struts.xml
<struts>
<constant name="struts.action.excludePattern" value=".*unfiltered.*,.*\\.nofilter"/>
...
</struts>
[url]http://struts.apache.org/2.2.1/docs/webxml.html[/url]
这样,servlet就不会被映射到。
解决:
<constant name="struts.action.excludePattern" value="/YourServlet"/>
参考:
Why the Filter is mapped with /* and how to configure explicit exclusions (since 2.1.7)
In the example above we've mapped the Struts 2 dispatcher to /*, so Struts 2 has a crack at all incoming requests. This is because Struts 2 serves static content from its jar files, including Dojo JavaScript files (if using S2.0, or the Dojo plugin in S2.1+) and FreeMarker templates for the Struts 2 tags that produce HTML.
If we change the filter mapping to something else, for example /*.html, we must take this in to account and extract the content that would normally be served from the Struts 2 jar files, or some other solution.
Since Struts 2.1.7, you are able to provide a comma seperated list of patterns for which when matching against the
request URL the Filter will just pass by. This is done via the configuration option struts.action.excludePattern, for example in your struts.xml
<struts>
<constant name="struts.action.excludePattern" value=".*unfiltered.*,.*\\.nofilter"/>
...
</struts>
[url]http://struts.apache.org/2.2.1/docs/webxml.html[/url]
解决Struts2配置冲突问题
本文详细介绍了在web.xml中配置servlet映射路径与Struts2 filermapping冲突时的解决方法,通过配置struts.action.excludePattern来避免servlet被忽略。
1245

被折叠的 条评论
为什么被折叠?



