Struts2 Static Content

In the Apache Struts2 Documentation Performance Tuning page one of the recommended tips for improving the performance of the framework is to avoid Struts serving the static content.

Struts tags and themes include a set of static resources – javascript libraries, CSS, Freemarker templates – which are included inside the Struts jar file. The framework, via a filter (org.apache.struts2.dispatcher.FilterDispatcher which then delegates to a “staticLoader” class), retrieves those resources from the jar files (unjar them on the fly) and serves them on request.

Although this works quite neatly – nice to have all classes and resources contained together – it adds an unnecessary overhead upon serving the http request.

The sections below presents how to turn this feature off: the static content is instead copied in the Web application root where is directly accessible.

Change Struts2 default settings

Add/set in

  ### Used by FilterDispatcher
  ### If true then Struts serves static content from inside its jar.
  ### If false then the static content must be available at <context_path>/struts

When set to false Struts wont try to load the static content from its jar files, but will look in a predefined directory called struts.

The struts folder must be created below the web application root and be accessible at <J2EE context path>/struts

Struts2 tags

Unjar the struts2-core-2.X.X.jar and copy into the struts folder the content (files and sub-folders) of:

  • org.apache.struts.static
  • template

Ajax tags

If you are also using the Ajax tags (tabbedpanel, datetimepicker, etc..) unjar the struts2-dojo-plugin-2.X.X.jar and copy into the struts folder the content of:

  • org.apache.struts.static
  • template

Custom JSP/Freemarker tag libraries

If you have created any custom JSP or freemarker tags and packaged them in a jar file, then similarly you should consider extracting the static content.

Move static content to a different server (Apache)

I couldn’t really find a a way to move the static content outside the web application, I guess – at this stage – you can only overwrite the Struts2 tags.

An option might be to filter certain requests (*/struts/*) at Apache level and redirect those to a different server rather than the servlet container. Not sure, will have to look at it first 😛


There is a series of tuning tips about Struts2 (all fair points), however serving the static content seems to be the most effective improvement. Hopefully soon I’ll be able to add more details/info about this topic, maybe after evaluating the real benefits of this.


2 Responses to Struts2 Static Content

  1. Nickman says:

    Hi, did you measure the impact of this improvement?

    • Hi
      we were happy just noticing a decrease of CPU processing during a web request handled by Struts.
      I guess an option is to profile Struts code to compare the 2 options but didnt get that far,
      or even JMeter could help you with that

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: