struts中使用tiles组件(原创)

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

请将下面所有”<---”字符串替换成”<”

1.在你的struts配置文件中加入下面的配置:

<---plug-in className="org.apache.struts.tiles.TilesPlugin" >

<---set-property property="definitions-config" value="/WEB-INF/tiles-def.xml" />

<---set-property property="definitions-parser-validate" value="true" />

<---/plug-in>

2.生成tiles-def.xml文件:

<---xml version="1.0" encoding="ISO-8859-1" >

<---!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>

3.生成layout.jsp布局文件:

<---%@ page contentType="text/html; charset=UTF-8" %><---%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%> <---html> <---head> <---title>布局设计<---/title> <---/head> <---body > <---%-- One table lays out all of the content --%> <---table width="100%" height="100%"> <---%-- Sidebar section --%> <---tr> <---td width="150" valign="top" align="left" bgcolor="#CCFFCC"> <---tiles:insert attribute="sidebar"/> <---/td> <---%-- Main content section --%> <---td valign="top" height="100%" width="*"> <---table width="100%" height="100%"> <---tr> <---%-- Header section --%> <---td height="15%"> <---tiles:insert attribute="header"/> <---/td> <---tr> <---tr> <---%-- Content section --%> <---td valign="top" height="*"> <---tiles:insert attribute="content"/> <---/td> <---/tr> <---tr> <---%-- Footer section --%> <---td valign="bottom" height="15%"> <---tiles:insert attribute="footer"/> <---/td> <---/tr> <---/table> <---/td> <---/tr> <---/table> <---/body> <---/html>

4.生成要使用的JSP文件sidebar.jsp,header.jsp,footer.jsp。

5.通过action-mappings配置你的tiles组件:

<---action-mappings>

<---action path="/index"

type="org.apache.struts.actions.ForwardAction"

parameter="index-definition">

<---/action>

<---/action-mappings>

parameter参数的值,是你在tiles-def.xml文件里某个的define的name。

别忘了在web.xml中加入

<---taglib>

<---taglib-uri>/WEB-INF/struts-tiles.tld<---/taglib-uri>

<---taglib-location>/WEB-INF/struts-tiles.tld<---/taglib-location>

<--/taglib>

同时还要保证你使用的是struts 1.1版本。

现在就可以动手为你的项目加入tiles应用了。

完成以上步骤,完成Tomcate部署并启动,通过http://localhost:8080/index.do可以看到下面的效果:

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航