使用弹簧3和瓷砖2.2.2时遇到问题。我无法显示动态页面标题。 这些是我的config / jsp文件:
layout.jsp
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><tiles:getAsString name="title" ignore="true"/></title>
</head>
<body>
<tiles:insertAttribute name="header" />
<div id="content-outer">
<div id="content-wrapper" class="container_16">
<tiles:insertAttribute name="body" />
<tiles:insertAttribute name="menu" />
</div>
</div>
<tiles:insertAttribute name="footer" />
</body>
</html>
Spring配置文件:
<bean id="tilesviewResolver"
class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
<property name="order" value="0" />
<property name="requestContextAttribute" value="requestContext" />
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
<property name="tilesProperties">
<props>
<prop key="org.apache.tiles.evaluator.AttributeEvaluator">org.apache.tiles.evaluator.el.ELAttributeEvaluator
</prop>
</props>
</property>
</bean>
tiles.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/views/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/views/inc/header.jsp" />
<put-attribute name="menu" value="/WEB-INF/views/inc/menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/views/inc/footer.jsp" />
</definition>
<definition name="item/itemDetail" extends="base.definition">
<put-attribute name="title" value="%{title}"/>
<put-attribute name="body" value="/WEB-INF/views/item/itemDetail.jsp" />
</definition>
</tiles-definitions>
页面标题不会被控制器呈现的标题值替换,而是替换为%{title}。
提前致谢
答案 0 :(得分:6)
我认为您的网页定义应该如下所示(请注意'表达'属性和'$'而不是'%'):
<definition name="item/itemDetail" extends="base.definition">
<put-attribute name="title" expression="${title}"/>
<put-attribute name="body" value="/WEB-INF/views/item/itemDetail.jsp" />
</definition>
您确定相关范围内有名为$ {title}的属性吗?您是否尝试直接在itemDetail.jsp页面中呈现$ {title}的值?
以下是相关文档,tiles使用servlet容器的EL支持: http://tiles.apache.org/2.1/framework/tutorial/advanced/el-support.html