在Struts2中集成Tiles2,我在tiles定义里直接定义action,如下:
<definition name="operationList" extends="baseOperationLayout">
<put-attribute name="title" value="operations.list.title" />
<put-attribute name="leftComponents" value="/queryOperationComponents.do " />
<put-attribute name="rightOperations" value="/WEB-INF/pages/system/operation-list.jsp" />
</definition>
还需在web.xml中增加配置:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.html</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
增加以上配置可以将action加入tiles模板了。但是我又遇到了一个问题,就是在operation-list.jsp中不能用s:iterator迭代出数据
<s:iterator value="operations" var="operation">
<tr>
<td>${operation.name}</td>
</tr>
</s:iterator>
后来改用jstl才能输出数据
<c:forEach items="${operations}" var="operation">
<tr>
<td><c:out value="${operation.label}" /></td>
</tr>
</c:forEach>