1、引包(我用的tiles依赖于struts2.1.6)
基本包(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
2、把tiles-jsp-2.0.6.jar包下的tiles-jsp.tld 拷贝到WEB-INF下WEB-INF/tiles-jsp.tld
3、创建tiles.xml放在WEB-INF下WEB-INF/tiles.xml 如下:
4.在web.xml添加如下:
org.apache.tiles.CONTAINER_FACTORY org.apache.struts2.tiles.StrutsTilesContainerFactory org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG /WEB-INF/tiles.xml struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 *.action org.apache.struts2.tiles.StrutsTilesListener
5.struts.xml(src)
xixi.haha
6.创建XXAction
package com; public class XXAction { public String execute(){ return "success"; } }
7.创建layout.jsp,注意存放路径要和tiles.xml一致
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %>Tiles演示
|
|
|
|
8.创建head.jsp,siderbar.jsp,contant.jsp,footer.jsp
9.测试,创建index.jsp
....
本文基于 http://tech.ddvip.com/2009-09/1252251869131168.html的修改的修改,谢谢他的分享。