spring 3 mvc中对title2的处理

在springmvc3中可以用title2的框架简化,下面是步骤:

1加上包,包如下图:

2在springmvc中设置title框架

/WebContent/WEB-INF/spring-servlet.xml

<beanid="viewResolver"class="org.springframework.web.servlet.view.UrlBasedViewResolver"><propertyname="viewClass">

<value>org.springframework.web.servlet.view.tiles2.TilesView</value>

</property>

</bean>

<beanid="tilesConfigurer"class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"><propertyname="definitions">

<list>

<value>/WEB-INF/tiles.xml</value>

</list>

</property>

</bean>

3建立一个title.xml

<?xmlversion="1.0"encoding="UTF-8"?>

<!DOCTYPEtiles-definitionsPUBLIC

"-//ApacheSoftwareFoundation//DTDTilesConfiguration2.0//EN"

"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>

<definitionname="base.definition"

template="/WEB-INF/jsp/layout.jsp">

<put-attributename="title"value=""/>

<put-attributename="header"value="/WEB-INF/jsp/header.jsp"/>

<put-attributename="menu"value="/WEB-INF/jsp/menu.jsp"/>

<put-attributename="body"value=""/>

<put-attributename="footer"value="/WEB-INF/jsp/footer.jsp"/>

</definition>

<definitionname="contact"extends="base.definition">

<put-attributename="title"value="ContactManager"/>

<put-attributename="body"value="/WEB-INF/jsp/contact.jsp"/>

</definition>

</tiles-definitions>

这里的contact是继承了base的模版框架了,

4layout.jsp文件

<%@tagliburi="http://tiles.apache.org/tags-tiles"prefix="tiles"%>

<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">

<title><tiles:insertAttributename="title"ignore="true"/></title>

</head>

<body>

<tableborder="1"cellpadding="2"cellspacing="2"align="center">

<tr>

<tdheight="30"colspan="2"><tiles:insertAttributename="header"/>

</td>

</tr>

<tr>

<tdheight="250"><tiles:insertAttributename="menu"/></td>

<tdwidth="350"><tiles:insertAttributename="body"/></td>

</tr>

<tr>

<tdheight="30"colspan="2"><tiles:insertAttributename="footer"/>

</td>

</tr>

</table>

</body>

</html>

相关推荐