tiles.xml 内容
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://tiles.apache.org/dtds/tiles-config_2_0.dtd" >
<tiles-definitions>
<definition name="simpleTpl" template="/WEB-INF/jsp/common/simpleTpl.jsp">
<put-attribute name="title" value="简易模版"></put-attribute>
<put-attribute name="header" value="/WEB-INF/jsp/common/header.jsp"></put-attribute>
<put-attribute name="body" value="/WEB-INF/jsp/common/body.jsp"></put-attribute>
<put-attribute name="footer" value="/WEB-INF/jsp/common/footer.jsp"></put-attribute>
</definition>
<definition name="index" extends="simpleTpl">
<put-attribute name="title" value="tiles测试"></put-attribute>
</definition>
</tiles-definitions>
web.xml 添加
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<context-param>
<param-name>tilesDefinitions</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
在WEB-INF下见jsp/common文件夹,里面创建
body.jsp
footer.jsp
header.jsp
simpleTpl.jsp
四个文件,前三个内容自定,simpleTpl.jsp中添加:
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<tiles:insertAttribute name="header"></tiles:insertAttribute><br>
<tiles:insertAttribute name="body"></tiles:insertAttribute><br>
<tiles:insertAttribute name="footer"></tiles:insertAttribute><br>
输入项目路径+index.action,就可以看到效果了
