web.xml filter-mapping not forwarding to struts

你。 提交于 2019-12-11 02:31:42

问题


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?


回答1:


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.




回答2:


That is because you do have a <servlet-mapping> for *.action, but no <servlet-mapping> for *.do



来源:https://stackoverflow.com/questions/1788631/web-xml-filter-mapping-not-forwarding-to-struts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!