SSH笔记五 整合Tiles2
时间:2011-01-18 BlogJava ju
今天的任务是添加Tiles2的支持,完成之后效果如下:
直接开始今天的内容了
1.在pom.xml中添加Tiles2的依赖
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>2.1.6</version>
</dependency>
2.添加Tiles2的配置文件tiles-def.xml,并添加tiles-jsp.tld文件(找到对应版本)(注意:DOCTYPE tiles-definitions PUBLIC 声明要注意版本,比如Tiles包是2.1的要申明为2.1,这里我们用的Tiles2.0.x,所以申明用2.0的配置文件
)
<?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="welcome" template="/template/layout.jsp">
<put-attribute name="title" value="Welcome"/>
<put-attribute name="head" value="/template/head.jsp"/>
<put-attribute name="content" value="/template/content.jsp"/>
<put-attribute name="foot" value="/template/foot.jsp"/>
</definition>
</tiles-definitions>
SSH笔记五 整合Tiles2(2)
时间:2011-01-18 BlogJava ju
3.创建Tiles模版以及需要的内容页
layout.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tiles-jsp.tld" prefix="tiles" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<title><tiles:insertAttribute name="title" /></title>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
</HEAD>
<BODY>
<table>
<tbody><tr>
<td><tiles:insertAttribute name="head"/></td></tr>
<tr>
<td><tiles:insertAttribute name="content"/></td></tr>
<tr>
<td><tiles:insertAttribute name="foot"/></td></tr>
</tbody></table>
</BODY>
</HTML>
head.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
this is head
content.jsp
<%@ page language="java&qu
|