我正在努力将Tiles 2与Spring集成,但是有问题。我有一个简单的tiles.jsp
页面。渲染tiles
视图会产生错误:org.apache.tiles.template.NoSuchAttributeException: Attribute 'title' not found.
我的配置和文件如下。
Tiles config:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:order="1">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="0">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/defs/templates.xml</value>
</list>
</property>
</bean>
/WEB-INF/defs/templates.xml中的定义:
<tiles-definitions>
<!-- Default Main Template -->
<definition name="base" template="/WEB-INF/pages/tiles.jsp">
<put-attribute name="title" value="Empty" type="string" />
<put-attribute name="header" value="/WEB-INF/tiles-templates/header.jsp" />
<put-attribute name="footer" value="/WEB-INF/tiles-templates/footer.jsp" />
<put-attribute name="body" value="/WEB-INF/tiles-templates/blank.jsp" />
</definition>
<definition name="tiles" extends="base">
<put-attribute name="title" value="Simple Tiles 2 Example"/>
</definition>
</tiles-definitions>
控制器:
@Controller
public class MainController {
@RequestMapping("/tiles")
public String tiles() {
return "tiles";
}
}
/WEB-INF/pages/tiles.jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<title><tiles:getAsString name="title" /></title>
<link rel="stylesheet" type="text/css" href="<c:url value="/css/main.css"/>" />
</head>
<body>
<div id="header">
<div id="headerTitle"><tiles:insertAttribute name="header" /></div>
</div>
<div id="content">
<tiles:insertAttribute name="body" />
</div>
<div id="footer">
<tiles:insertAttribute name="footer" />
</div>
</body>
</html>
答案 0 :(得分:2)
已解决!我已从suffix
删除了prefix
和tilesViewResolver
个属性,一切都开始有效。
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="0">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>