Tiles框架

[b]1.在你的struts配置文件struts-config.xml中加入下面的配置:[/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"/>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值