web.xml配置web
<filter> <filter-name>struts-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>struts-execute</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts-prepare</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts-execute</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
注意: <filter-mapping>的順序必須是以上順序,struts-prepare-->sitemesh-->struts-execute.不然的話裝飾器不會起做用.apache
Sitemesh xml配置app
<!-- 配置裝飾器 --> <decorators defaultdir="/WEB-INF/decorators"><!-- 裝飾器頁面目錄 --> <!-- 不裝飾的頁面 --> <excludes> <pattern>/login.jsp</pattern> <pattern>/qiantai/userinfo/*</pattern> <pattern>*My97DatePicker.htm</pattern> </excludes> // 這個裝飾器裝飾那個路徑下的, 這裏能夠配置多個裝飾器 <decorator name="main" page="houtai/main.jsp"> <pattern>/*</pattern> </decorator> <decorator name="menu" page="houtai/menu.jsp" /> <decorator name="header" page="houtai/header.jsp" /> <decorator name="footer" page="houtai/footer.jsp" /> // 前臺裝飾樣式 <decorator name="qt_main" page="qiantai/main.jsp"> <pattern>/qiantai/*</pattern> </decorator> <decorator name="qt_header" page="qiantai/header.jsp" /> <decorator name="qt_footer" page="qiantai/footer.jsp" /> </decorators>
注意: 裝飾器配置時不一樣裝飾器中<decorator>標籤中的name屬性的值不能同樣,不然會出現裝飾頁面混淆的狀況.webapp