当前位置: 代码迷 >> Web前端 >> Struts2 Tiles 配备篇 转载
  详细解决方案

Struts2 Tiles 配备篇 转载

热度:496   发布时间:2012-09-11 10:49:03.0
Struts2 Tiles 配置篇 转载

一.基本包(6个)

?? 1.commons-logging-1.0.4.jar

?? 2.commons-fileupload-1.2.1.jar

?? 3.ognl-2.6.11.jar

?? 4.struts2-core-2.1.6.jar

?? 5.xwork-2.1.2.jar

?? 6.freemarker-2.3.13.jar

二.整合tiles必须包(7个)

?? 1.struts2-tiles-plugin-2.1.6.jar

?? 2.tiles-api-2.0.6.jar

?? 3.tiles-core-2.0.6.jar

?? 4.tiles-jsp-2.0.6.jar

?? 5.commons-digester-1.8.jar

?? 6.commons-collections-3.2.jar

?? 7.commons-beanutils-1.7.0.jar

三.把tiles-jsp-2.0.6.jar包下的tiles-jsp.tld 拷贝到WEB-INF下.WEB-INF/tiles-jsp.tld

四.创建tiles.xml .放在WEB-INF下.WEB-INF/tiles.xml 如下:

view plaincopy to clipboardprint?
<?xml version="1.0" encoding="UTF-8"?>?
<!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="xixi.haha " template="layout.jsp">?
??????? <put-attribute name="header" value="head.jsp" />?
??????? <put-attribute name="sidebar" value="sidebar.jsp" />?
??????? <put-attribute name="contant" value="contant.jsp" />?
??????? <put-attribute name="footer" value="foot.jsp" />?
??? </definition>?
</tiles-definitions>?
<?xml version="1.0" encoding="UTF-8"?>
<!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="xixi.haha " template="layout.jsp">
??????? <put-attribute name="header" value="head.jsp" />
??????? <put-attribute name="sidebar" value="sidebar.jsp" />
??????? <put-attribute name="contant" value="contant.jsp" />
??????? <put-attribute name="footer" value="foot.jsp" />
??? </definition>
</tiles-definitions>

五.在web.xml添加如下:

view plaincopy to clipboardprint?
<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>?
<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>

六.修改struts.xml

view plaincopy to clipboardprint?
<!DOCTYPE struts PUBLIC??
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"??
"http://struts.apache.org/dtds/struts-2.0.dtd">?
?? <struts>?
??????? <package name="default" extends="tiles-default ">?
??????????? <action name="XXAction" class="com.XXAction">?
??????????????? <result name="success" type="tiles ">xixi.haha </result>?
??????????? </action>?
??????? </package>?
?? </struts>?
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
?? <struts>
??????? <package name="default" extends="tiles-default ">
??????????? <action name="XXAction" class="com.XXAction">
??????????????? <result name="success" type="tiles ">xixi.haha </result>
??????????? </action>
??????? </package>
?? </struts>

七.创建layout.jsp,注意存放路径要和tiles.xml一致.

view plaincopy to clipboardprint?
...??
??? <%@ taglib uri="/WEB-INF/tiles-jsp.tld " prefix="tiles"%>?
??? ...??
??? <table>?
??????? <tr><td><tiles:insertAttribute name="header"></tiles:insertAttribute></td></tr>?
??????? <tr><td><tiles:insertAttribute name="sidebar"></tiles:insertAttribute></td></tr>?
??????? <tr><td><tiles:insertAttribute name="contant"></tiles:insertAttribute></td></tr>?
??????? <tr><td><tiles:insertAttribute name="footer"></tiles:insertAttribute></td></tr>?
?? </table>?
??? ....?
...
??? <%@ taglib uri="/WEB-INF/tiles-jsp.tld " prefix="tiles"%>
??? ...
??? <table>
??????? <tr><td><tiles:insertAttribute name="header"></tiles:insertAttribute></td></tr>
??????? <tr><td><tiles:insertAttribute name="sidebar"></tiles:insertAttribute></td></tr>
??????? <tr><td><tiles:insertAttribute name="contant"></tiles:insertAttribute></td></tr>
??????? <tr><td><tiles:insertAttribute name="footer"></tiles:insertAttribute></td></tr>
?? </table>
??? ....

八.创建head.jsp,siderbar.jsp,contant.jsp,footer.jsp

九.测试,创建index.jsp

view plaincopy to clipboardprint?
....??
<form action="XXAction.do" method="post">?
<input type="submit"/>?
</form>?
....
<form action="XXAction.do" method="post">
<input type="submit"/>
</form>

  相关解决方案