Struts2 serves template files that way because they are packaged in a JAR. For files that are local to your web application, you should just serve them from your WAR file (e.g., src/main/webapp if you use the Maven standard directory layout). For example, you can just create a "js" directory in your web root and place your JavaScript files there. Then just reference them as "/yourContextRoot/js/foo.js".
- What version of Struts2 are you
using?
- What is your action extension
configured to be? (e.g., the value of
your struts.action.extension
property)
In Struts 2.0.x, the default extension was "action", so requests that don't end in "action" should pass through to other filters, servlets, or to the file system automatically. If you change that value to be empty, then Struts2 will match against all URLs and nothing will get through to the file system.
In Struts 2.1.x, the default extension was changed to "action,,", which matches both ".action" and also no extension. This should still pass requests that have an extension other than .action straight through (e.g., css, js, png, etc.)
As of version 2.2.x of Struts2, you can also include a property in the struts.properties (or as a constant in the struts.xml) file, such as:
struts.action.excludePattern=/js/.*
Struts2 will allow any matching requests to pass through.
Any of those approaches should allow you to serve static files from the root of your war file. You should not need to place static web content in your Java package structure.