struts框架中使用tiles组件代码实例
来源:互联网 发布:2017全国进出口数据 编辑:程序博客网 时间:2024/06/05 07:02
转自:http://java.chinaitlab.com/Struts/902066.html
参考:http://tech.ccidnet.com/art/3737/20050210/473149_1.html
另外参考:http://blog.csdn.net/reallyafei/article/details/1501623 ,这里介绍了相关的一些原理
1.在你的struts配置文件struts-config.xml中加入下面的配置:
<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>
ps:或者
<plug-inclassName="org.apache.struts.tiles.TilesPlugin">
<set-propertyproperty="definitions-config"
value="/WEB-INF/tiles-def.xml"/>
<set-propertyproperty="moduleAware"value="true"/>
</plug-in>
其中:
moduleAware:(可选)
指定Tiles的定义池是否已模块对应化。如果是true(默认),对应每一个Struts模块都有一个定义池。如果是false,就会有一个为所有模块共用的定义池。对应后者,仍然需要每一个模块都对应定义一个plug-in插件。定义池将要以在第一个plug-in插件(一般是与默认的模块相关联的那个插件)中发现的参数值来初始化定义池。
true:Tiles框架是模块对应。
false:Tiles框架在所有的模块中只有一个共用的定义池(默认)。
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”
“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=GBK” %>
<%@ taglib uri=“/tags/struts-tiles” prefix=“tiles”%>
<html>
<head> <title>布局设计</title> </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>
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.
ps:另外的写法是:
<actionpath="/UploadSelect"type="org.springframework.web.struts.DelegatingActionProxy"name="UploadSelectForm"scope="request">
<forwardname="failure"path="cm.portalLayout.operationError"></forward>
<forwardname="success"path="cm.uploadLayout"></forward>
</action>
6.别忘了在web.xml中加入
<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
同时还要保证你使用的是struts 1.1版本。
现在就可以动手为你的项目加入tiles应用了。
完成以上步骤,完成Tomcate部署并启动,通过127.0.0.1:8080/strutsTiles/index.do可以看到效果。
运行下面两个文件是同样的效果:
1、index1.jsp
<%@ page contentType=“text/html; charset=gb2312” %>
<%@ taglib uri=“/tags/struts-tiles” prefix=“tiles” %>
使用逻辑名
<tiles:insert definition=“index-definition”/>
2、index.jsp
<%@ page contentType=“text/html; charset=gb2312” %>
<%@ taglib uri=“/tags/struts-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>
- struts框架中使用tiles组件代码实例
- struts中使用tiles组件
- Struts Tiles框架实例
- struts中使用tiles组件 更新中。。。
- struts中使用tiles组件(原创)
- Struts框架中 's Tiles使用入门教程
- Struts 框架-----使用 Tiles
- Struts Tiles框架使用
- Struts Tiles框架使用
- Struts Tiles框架使用
- Struts Tiles框架使用
- Struts中使用tiles
- Struts Tiles框架的使用
- Struts中使用Tiles框架实现复合式网页步骤
- Struts中tiles的使用
- 在struts里面使用Tiles框架
- struts tiles实例
- Struts:Tiles框架
- A FLASH Bootloader for PIC16 and PIC18 Devices--硬译(五)
- C/C++ union用法(转)
- commons-fileupload和dwr实现带有进度条的文件上传
- 短语、直接短语、句柄、素短语
- C#将datatable生成easyui的绑定tree 的json数据格式
- struts框架中使用tiles组件代码实例
- hdu 1429搜索
- c# 使用FileStream打开并清空文件、将一文件内容另存为到新文件
- ImageButton组件的应用
- 大数据量采用什么方式建表
- typedef define
- URL编码
- 【JAVA 基础】JAVA常见异常集锦(持续更新)
- ID3算法的python实现