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

Compare with Current View Page History

Version 1 Current »

Using Sitemesh with Struts 2 is very easy the only basic configuration change you need to make is to insert the SiteMeshFilter in the correct position of the filter list. Instead of using the normal StrutsPrepareAndExecuteFilter you need to use the two filters StrutsPrepareFilter and StrutsExecuteFilter and insert the SiteMeshFilter between them.

web.xml changes:

<filter>
<filter-name>struts2-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter>
<filter-name>struts2-execute</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2-prepare</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>struts2-execute</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Note: the filter order is determined by the order of the filter-mapping's within the web.xml file so you must ensure the above order is used.

There is also a struts2-sitemesh-plugin but his is only needed if you want to write your sitemesh decorators in freemarker or velocity, it isn't needed if you use JSP decorators.

This was tested with:
Struts 2.2.1
Sitemesh 2.4.1

  • No labels