spring 3 mvc中对title2的处理

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

1 加上包,包如下图:
  spring 3 mvc中对title2的处理

2 在spring mvc中设置title框架
  /WebContent/WEB-INF/spring-servlet.xml
<bean id="viewResolver"    class="org.springframework.web.servlet.view.UrlBasedViewResolver">     <property name="viewClass">     
   <value>             org.springframework.web.servlet.view.tiles2.TilesView         </value>
     </property>
</bean>
<bean id="tilesConfigurer"    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">     <property name="definitions">    
    <list>      
      <value>/WEB-INF/tiles.xml</value>   
     </list> 
   </property>
</bean>

3 建立一个title.xml
<?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="base.definition"
template="/WEB-INF/jsp/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/jsp/header.jsp" />
<put-attribute name="menu" value="/WEB-INF/jsp/menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" />
</definition>

<definition name="contact" extends="base.definition">
<put-attribute name="title" value="Contact Manager" />
<put-attribute name="body" value="/WEB-INF/jsp/contact.jsp" />
</definition>

</tiles-definitions>
这里的contact是继承了base的模版框架了,

4 layout.jsp文件
  <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<body>
<table border="1" cellpadding="2" cellspacing="2" align="center">
<tr>
<td height="30" colspan="2"><tiles:insertAttribute name="header" />
</td>
</tr>
<tr>
<td height="250"><tiles:insertAttribute name="menu" /></td>
<td width="350"><tiles:insertAttribute name="body" /></td>
</tr>
<tr>
<td height="30" colspan="2"><tiles:insertAttribute name="footer" />
</td>
</tr>
</table>
</body>
</html>

你可能感兴趣的:(apache,spring,xml,mvc,框架)