[b]1.在你的struts配置文件struts-config.xml中加入下面的配置:[/b]
[b]2.生成tiles-def.xml文件(/WEB-INF/tiles-def.xml):[/b]
[b]3.生成layout.jsp布局文件:[/b]
[b]4.生成要使用的JSP文件sidebar.jsp,header.jsp,footer.jsp。 [/b]
[b]5.通过action-mappings配置你的tiles组件:[/b]
[b]只要tilesExam.do的响应一到达,在经过action的内部处理以后,就会转发复合视图来显示。[/b]
[b]6.TilesExamAction类[/b]
[b]7.index.jsp[/b]
[b]8.上面的jsp页面也可以写为[/b]
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<!-- Path to XML definition file -->
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>
[b]2.生成tiles-def.xml文件(/WEB-INF/tiles-def.xml):[/b]
<?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="base-definition" path="/layout.jsp">
<put name="sidebar" value="sidebar.jsp"/>
<put name="header" value="header.jsp"/>
<put name="content" value=""/>
<put name="footer" value="footer.jsp"/>
</definition>
<definition name="index-definition" extends="base-definition">
<put name="content" value="indexContent.jsp"/>
</definition>
</tiles-definitions>
[b]3.生成layout.jsp布局文件:[/b]
<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>layout.jsp</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<table width="100%" height="100%">
<tr>
<td width="150" valign="top" align="left" bgcolor="#CCFFCC">
<tiles:insert attribute="sidebar"/>
</td>
<td valign="top" height="100%" width="*">
<table width="100%" height="100%">
<tr> <td height="15%"> <tiles:insert attribute="header"/> </td> </tr>
<tr> <td valign="top" height="*"> <tiles:insert attribute="content"/> </td></tr>
<tr> <td valign="bottom" height="15%"><tiles:insert attribute="footer"/></td></tr>
</table>
</td>
</tr>
</table>
</body>
</html:html>
[b]4.生成要使用的JSP文件sidebar.jsp,header.jsp,footer.jsp。 [/b]
[b]5.通过action-mappings配置你的tiles组件:[/b]
<action path="/tilesExam" type="com.yourcompany.struts.action.TilesExamAction">
<set-property property="cancellable" value="true" />
<forward name="success" path="index-definition"></forward>
</action>
[b]只要tilesExam.do的响应一到达,在经过action的内部处理以后,就会转发复合视图来显示。[/b]
[b]6.TilesExamAction类[/b]
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.yourcompany.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* MyEclipse Struts
* Creation date: 04-19-2010
*
* XDoclet definition:
* @struts.action validate="true"
*/
public class TilesExamAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
return mapping.findForward("success");
}
}
[b]7.index.jsp[/b]
<%@ page contentType="text/html; charset=gb2312" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<tiles:insert page="layout.jsp" flush="true">
<tiles:put name="sidebar" value="sidebar.jsp"/>
<tiles:put name="header" value="header.jsp"/>
<tiles:put name="content" value="indexContent.jsp"/>
<tiles:put name="footer" value="footer.jsp"/>
</tiles:insert>
[b]8.上面的jsp页面也可以写为[/b]
<%@ page contentType="text/html; charset=gb2312" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<tiles:insert definition="index-definition"/>