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.
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 struts2.properties:
### 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 struts.serve.static=false
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
Unjar the struts2-core-2.X.X.jar and copy into the struts folder the content (files and sub-folders) of:
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:
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.