我正在使用spring开发netbeans上的web应用程序,我想要包含apache Tiles3。部署页面时,它无法正确呈现,只显示纯文本文件的路径。任何人都可以告诉我,如果我做错了什么?
这是我的Dispatcher-servlet.xml
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<import resource="beans.xml" />
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles3.TilesView
</value>
</property>
</bean>
<bean id="viewResolverJsp"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
这是我的tiles.xml
<tiles-definitions>
<definition name="base.definition" template="WEB-INF/jsp/tiles/template.jsp">
<put-attribute name="title" value=""/>
<put-attribute name="header" value="WEB-INF/jsp/tiles/header.jsp"/>
<put-attribute name="menu" value="WEB-INF/jsp/tiles/menu.jsp"/>
<put-attribute name="body" value=""/>
<put-attribute name="footer" value="WEB-INF/jsp/tiles/footer.jsp"/>
</definition>
<definition name="index" extends="base.definition">
<put-attribute name="title" value="Strutsss" />
<put-attribute name="body" value="WEB-INF/index.jsp" />
</definition>
<definition name="test" extends="base.definition">
<put-attribute name="title" value="Strutsss" />
<put-attribute name="body" value="WEB-INF/jsp/test.jsp" />
</definition>
template.jsp
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<!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" ignore="true" />
</title>
</head>
<body>
<table align="center">
<tr>
<td colspan="2" id="headerTD">
<tiles:insertAttribute name="header" />
</td>
</tr>
<tr>
<td id="menu">
<tiles:insertAttribute name="menu" />
</td>
<td>
<div id="body">
<tiles:insertAttribute name="body" />
</div>
</td>
</tr>
<tr>
<td colspan="2">
<tiles:insertAttribute name="footer" />
</td>
</tr>
</table>
</body>
答案 0 :(得分:0)
修改
请在
中更改您的解析器<bean id="tilesViewResolver"
class="org.springframework.web.servlet.view.tiles3.TilesViewResolver">
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
删除当前的viewResolverJsp
请尝试更改
value="WEB-INF/index.jsp" />
in
value="/WEB-INF/index.jsp" />
的pom.xml
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.5</version>
</dependency>