Struts2 Tiles框架页面;
1,加入类库;(struts-2.3.1.2-all类库中复制)
struts2-tiles-plugin-2.3.1.2
tiles-api-2.0.6,tiles-core-2.0.6,tiles-jsp-2.0.6(这3个可以在http://tiles.apache.org/download.html 下载最新的;)
commons-digester-2.0,commons-beanutils-1.7.0,
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
org.apache.tiles.web.startup.TilesListener (当上面个有问题用这个)
</listener-class>
</listener>
3 ,页面:框架主页面base.jsp
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<title><tiles:getAsString name="title" /></title>
<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="menu" />
......
4,Struts.xml下:
<include file="/service/actionOpra.xml"/> //我的Struts.xml中省略了包。
actionOpra.xml中,
<package name="loginOpra" namespace="/WebsiteBackstage" extends="tiles-default">
<action name="LoginOn" class="service.LoginService">
<result name="SUCCESS" type="tiles">baseLayout</result>
<result name="input">/WebsiteBackstage/login.jsp</result>
</action>
//1),继承extends="tiles-default";2),返回类型type="tiles";3),tiles.xml对应的definition 的name名baseLayout。
5,Web-inf下tiles.xml:
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/base.jsp">
<put-attribute name="title" value="Tiles Show"/>
<put-attribute name="header" value="/tiles/header.jsp"/>
<put-attribute name="menu" value="/tiles/menu.jsp"/>
<put-attribute name="body" value="/tiles/body.jsp"/>
<put-attribute name="footer" value="/tiles/footer.jsp"/>
</definition>
</tiles-definitions>
参考:
http://wap.iteye.com/blog/181067
http://www.blogjava.net/caizh2009/archive/2010/04/26/319392.html