如何在Servlet中使用Tiles

时间:2015-07-22 06:50:42

标签: jsp servlets

我的tiles.xml文件看起来像
    <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd"> <tiles-definitions> <definition name="homepage" template="/layouts/classic.jsp"> <put-attribute name="header" value="/tile1.jsp" /> <put-attribute name="body" value="/body.jsp" /> </definition> </tiles-definitions>
我创建了一个classic.jsp,它是主布局

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<title></title>
</head>
<body>
<table>
<tr>  
<td>
<tiles:insertAttribute name="header" />
</td>
</tr>
<tr>
<td>
<tiles:insertAttribute name="body" />    
</td>
</tr>
</table>
</body>
</html>

我创建了tile1.jsp和body.jsp
我在WEB-INF / lib中包含了这些jar
commons-beanutils-1.8.0.jar commons-digester-2.0.jar jcl-over-slf4j-1.5.8.jar servlet-api.jar slf4j-api-1.5.8.jar tiles-api-2.2.2.jar tiles-core-2.2.2.jar tiles-jsp-2.2.2.jar tiles-servlet-2.2.2.jar tiles-servlet-wildcard-2.2.2.jar tiles-template-2.2.2.jar

在与tile相关的web.xml中添加什么内容?

1 个答案:

答案 0 :(得分:0)

您需要一个视图解析器和一个tile配置器

<bean id="viewResolverTiles"
    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>