Struts2.0中Tiles框架使用(我想使index页面根据用户选中某一模板文件来动态的生成index页面?请问该怎么解决)

tiger_cdx 2007-09-29 04:25:26
目前项目中要用到tiles框架,研究了一段时间tiles标签,但是在用的过程中,layout的文件我已经可以定制,但是index页面中,插入的模板文件是根据用户的选择而生成,但是tiles标签<tiles insertTemplate> 标签属性 template的值怎么来根据传入的不同模板文件来变化呢??已经试过用OGNL语言,好象此路径行不通,也不能嵌套struts2.0的标签,求救各位大仙,如果有懂的请不吝赐教......
...全文
1015 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zerepxan 2011-03-13
  • 打赏
  • 举报
回复
不错,我也试一试!
loaferwang 2008-11-30
  • 打赏
  • 举报
回复
上面是一位仁兄的,你试试
loaferwang 2008-11-30
  • 打赏
  • 举报
回复
最近闲着无事,琢磨了一下struts2.06的tiles使用。以下是一些简单使用的步骤。
1.在WEB-INF/lib下加入所需的jar包
commons-digester-1.6.jar,
xwork-2.0.1.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
2.修改web.xml 为以下内容
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.apache.tiles.listener.TilesListener</listener-class>
</listener>
</web-app>

3.在WEB-INF下添加tiles.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://struts.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="showcase.index" template="/tiles/layout.jsp">
<put name="title" value="Tiles Showcase"/>
<put name="header" value="/tiles/header.jsp"/>
<put name="body" value="/tiles/body.jsp"/>
</definition>
</tiles-definitions>
4.struts.xml 为:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<include file="struts-conf/struts-test.xml" />
</struts>
5.struts-test.xml文件为:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="test" namespace="/test" extends="tiles-default">
<!-- <result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
</result-types> -->
<global-results>
<result name="login"><param name="location">/user/login.jsp</param></result>
</global-results>
<action name="sample" class="com.lhx.test.action.TilesAction" method="inputIndex" >
<result name="success" type="tiles">showcase.index</result>
</action>
</package>
</struts>
6.注意要在每个jsp文件中加入<%@ page contentType="text/html; charset=UTF-8"%>
china2001ok 2008-01-04
  • 打赏
  • 举报
回复
也在搞这个 搞清楚了 回答你
tiger_cdx 2007-10-18
  • 打赏
  • 举报
回复
自己顶
tiger_cdx 2007-09-30
  • 打赏
  • 举报
回复
难道没有人用过tiles框架么??

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧