struts2整合tiles

1.在WEB-INF/lib下加入所需的jar包

commons-digester-1.6.jar,

tiles-core-2.0-20070207.130156-4.jar,
tiles-api-2.0-20070207.130156-4.jar,
struts2-tiles-plugin-2.0.6.jar,
struts2-core-2.0.6.jar
xwork-2.0.1.jar,
2. 以下内容添加到web.xml
< context-param >
< param-name > org.apache.tiles.CONTAINER_FACTORY </ param-name >
< param-value >
org.apache.struts2.tiles.StrutsTilesContainerFactory
</ param-value >
</ context-param >
< context-param >
< param-name > org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</ param-name >
< param-value > /WEB-INF/tiles.xml </ param-value >
</ context-param >
< listener >
< listener-class >
org.apache.struts2.tiles.StrutsTilesListener
</ listener-class >
</ listener >
3.在WEB-INF下添加和tiles.tld和tiles.xml文件,其中tiles.tld内容为tiles-core-2.0-20070207.130156-4.jar包中META_INF/tiles-core.tld的内容。
(struts-tiles-1.3.10.jar解压后META-INF\tld下会有5个tld文件,其中一个是struts-tiles.tld)
tiles.xml内容:
<? xml version = "1.0" encoding = "GB2312" ?>
<! DOCTYPE tiles-definitions PUBLIC
"-//Apache SoftwareFoundation//DTD Tiles Configuration 2.0//EN"
"http://jakarta.apache.org/struts/dtds/tiles-config.dtd" >
< tiles-definitions >
< definition name = "myapp.homepage" template = "layout.jsp" >
< put name = "title" value = "Tiles tutorial homepage" />
< put name = "header" value = "/tiles/header.jsp" />
< put name = "menu" value = "/tiles/menu.jsp" />
< put name = "body" value = "/tiles/cBody.jsp" />
< put name = "footer" value = "/tiles/footer.jsp" />
</ definition >
</ tiles-definitions >
4.struts.xml 为:
<! DOCTYPE struts PUBLIC
"-//Apache SoftwareFoundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd" >
< struts >
< package name = "default" extends = "tiles-default" >
<action name="go"class="com.action.MyAction">
<!--resultname="success">/next.jsp</result-->
< result name = "success" type = "tiles" > myapp.homepage </ result >
</ action >
</ package >
</ struts >
红色部分根据自己项目定。注意 extends = "tiles-default"
5创建 layout.jsp
<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri = "WEB-INF/tiles.tld " prefix = "tiles" %>
< html >
< head >
< title ></ title >
</ head >
< body >
< table width = "768px" height = "800px" border = "2" align = "center" >
< tr >
< td colspan = "2" align = "center" valign = "top" width = "768px" height = "100px" bgcolor = "#80ff80" >
< tiles:insertAttribute name = "header" />
</ td >
</ tr >
< tr >
< td align = "center" width = "150px" height = "800px" bgcolor = "#00ff00" >
< tiles:insertAttribute name = "menu" />
</ td >
< td align = "right" width = "618px" height = "800px" bgcolor = "#ff80c0" >
< tiles:insertAttribute name = "body" />
</ td >
</ tr >
< tr >
< td colspan = "2" bgcolor = "#00ff40" height = "100px" >
< tiles:insertAttribute name = "footer" />
</ td >
</ tr >
</ table >
</ body >
</ html >
6. 根据
< put name = "title" value = "Tiles tutorialhomepage" />
< put name = "header" value = "/tiles/header.jsp" />
< put name = "menu" value = "/tiles/menu.jsp" />
< put name = "body" value = "/tiles/cBody.jsp" />
< put name = "footer" value = "/tiles/footer.jsp" />
WebRoot 下创建 tiles 目录和相应 jsp 文件
7.OK 了!下载源代码到我的 CSDN 资源http://download.csdn.net/user/haoxing272
null
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值