您的位置:首页 > 编程语言 > Java开发

struts2+tiles环境搭建

2011-05-10 17:59 302 查看
1. base jars for struts2:



2. jars for tiles:



3. Put tiles-jsp.tld under WEB-INF and create file tiles.xml (tiles definition) in WEB-INF
tiles.xml
<tiles-definitions>
<definition name="ibeidou.mainLayout" template="/layout.jsp">
<put-attribute name="title" value="welcome to struts2" />
<put-attribute name="contant" value="/main.jsp" /><!-- '/' is must-->
<put-attribute name="footer" value="/footer.jsp" />
</definition>
</tiles-definitions>
layout.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><tiles:getAsString name="title" /></title>
</head>
<body>
<tiles:insertAttribute name="contant"></tiles:insertAttribute>
<hr></hr>
<tiles:insertAttribute name="footer"></tiles:insertAttribute>
</body>
</html>

4. In struts.xml
<package name="mytiles" extends="tiles-default"> but no longer
<package name="myaction" extends="struts-default"><!-- The package name should be unique -->
<action name="welcome" class="com.ibeidou.struts2.test01.HelloAction">
<result name="success" type="tiles">ibeidou.mainLayout</result>
</action>

5. web.xml add tiles listener
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: