web.xml 过滤器映射不转发到 struts
我正在尝试做一些微不足道的事情,但看不到我错过了什么。我有以下 web.xml...
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
当我使用像“http://localhost:8080/ 这样的 URL 时gallery.action”,一切正常(因为“gallery”在 struts.xml 等中正确配置)。
但是,如果我点击“http://localhost:8080/gallery.do” - 我得到 404 响应。 Tomcat 似乎没有将请求转发到 struts,因为 struts 端没有日志记录。 Tomcat 日志只显示 404。
我尝试将过滤器映射更改为 *.blah,但除了 *.action 之外没有任何效果。我在默认的 web.xml 文件中没有看到任何冲突的信息。
有人知道我错过了什么吗?
I am trying to do something trivial and can't see what I'm missing. I have the following web.xml...
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
And when I use a URL like "http://localhost:8080/gallery.action", everything works just fine (because "gallery" is configured properly in struts.xml, etc, etc).
If, however, I hit "http://localhost:8080/gallery.do" instead - I get a 404 response. Tomcat does not appear to be forwarding the request to struts as there is no logging on struts side. Tomcat logs just show the 404.
I've tried changing the filter-mapping to *.blah and nothing works except for *.action. I don't see any conflicting information in the default web.xml file.
Anyone know what I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,Struts2 默认情况下仅识别 .action 扩展名,需要使用 struts.properties 文件根据需要配置其他扩展名:
struts.action.extension=action,do,etc
考虑到大多数文档讨论如何转发到 struts,这是非常具有误导性的专门使用过滤器映射。
Apparently Struts2 only recognizes the .action extension by default and one needs to configure other extensions as desired using struts.properties file:
struts.action.extension=action,do,etc
This was very misleading given that most documentation discusses how to forward to struts using filter-mapping exclusively.
这是因为您确实有 *.action 的
,但没有 *.do 的That is because you do have a
<servlet-mapping>
for *.action, but no<servlet-mapping>
for *.do