You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Struts can serve static content like css and javascript files. This feature is enabled by default, but can be disabled by setting:

<constant name="struts.serve.static" value="false" />

If you disable this feature, but use the xhtml, or css_xhtml theme, make sure that the javascript and css files shipped inside the core jar are extracted to your web application directory.

Custom Static Content Loaders

Static content is served by an implementation of org.apache.struts2.dispatcher.StaticContentLoader. To write your own StaticContentLoader, implement StaticContentLoader and define a bean for the class:

 <bean type="org.apache.struts2.dispatcher.StaticContentLoader" class="MyStaticContentLoader" name="myLoader" />
 <constant name="struts.staticContentLoader" value="myLoader" />

Default Content Loader

Struts provides a default implementation of StaticContentLoader which is org.apache.struts2.dispatcher.DefaultStaticContentLoader. This loader will handle urls that start with "/static/".

This content loader can serve static content from the classpath, so when writing a plugin, you can put a file inside your plugin's jar like "/static/image/banner.jpg" and it will be served when the url "/static/image/banner.jpg" is requested.

This loader is not optimized to handle static content, and to improve performance, it is recommended that you extract your static content to the web application directory, and let the container handle them.

  • No labels