Ben Benson
Ben Benson

Reputation: 93

web.xml filter-mapping not forwarding to struts

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?

Upvotes: 2

Views: 6004

Answers (2)

Ben Benson
Ben Benson

Reputation: 93

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.

Upvotes: 2

Salandur
Salandur

Reputation: 6453

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

Upvotes: -1

Related Questions