步骤-:复习jsp:include
1,所需jsp文件--->Header.jsp; Left.jsp; Content.jsp; Foot.jsp ; index.jsp
2, Header.jsp; Left.jsp; Content.jsp; Foot.jsp 这四个jsp文件内容一样,只是单词不同。
这里亮出
Header.jsp
//
<%@page contentType="text/html; charset=utf-8" %>
<html>
<head>
<title>Header.jsp</title>
</head>
<body>
<p align="center">Header</p>
</body>
</html>
///
3,写index.jsp
index.jsp
///
<%@page contentType="text/html; charset=utf-8" %>
<html>
<head>
<title>index.jsp</title>
</head>
<body>
<table>
<tr>
<td colspan="2"><jsp:include flush="true" page="Header.jsp"/></td>
</tr>
<tr>
<td><jsp:include flush="true" page="Left.jsp"/></td>
<td><jsp:include flush="true" page="Content.jsp"/></td>
</tr>
<tr>
<td colspan="2"><jsp:include flush="true" page="Foot.jsp"/></td>
</tr>
</table>
</body>
</html>
步骤二:正题
1,--> Add Struts
2, -->增加两个jsp文件 one.jsp; two.jsp 具体内容同Header.jsp
3, --> 在web.xml中配置tld
/
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
</jsp-config>
4, -->在struts-config.xml中加入tiles插件
///
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />
<set-property property="definitions-parser-validate"
value="true" />
</plug-in>
//
5,-->完成tiles-defs.xml
///
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
<tiles-definitions>
<definition name="index-definition" path="/index_tiles.jsp">
<put name="header" value="Header.jsp"/>
<put name="left" value="Left.jsp"/>
<put name="content" value=""/>
<put name="foot" value="Foot.jsp"/>
</definition>
<definition name="one-definition" extends="index-definition">
<put name="content" value="one.jsp"></put>
</definition>
<definition name="two-definition" extends="index-definition">
<put name="content" value="two.jsp"></put>
</definition>
</tiles-definitions>
///
6,-->写one-definition 的模板文件index_tiles.jsp
<%@page contentType="text/html; charset=utf-8" %>
<%@taglib uri="/WEB-INF/struts-tiles" prefix="tiles" %>
<html>
<head>
<title>index_tiles.jsp</title>
</head>
<body>
<table>
<tr>
<td colspan="2"><tiles:insert attribute="header"/></td>
</tr>
<tr>
<td><tiles:insert attribute="left"/></td>
<td><tiles:insert attribute="content"/></td>
</tr>
<tr>
<td colspan="2"><tiles:insert attribute="foot"/></td>
</tr>
</table>
</body>
</html>
///
7,-->加一个ForwardAction配置, 这里只举one的例子
///
<action path="/toOne"
type="org.apache.struts.actions.ForwardAction"
parameter="one-definition"/>
//
8,-->运行 http://localhost:8080/【项目名】/toOne.do