修改 我正在尝试使用Spring MVC将Tiles与Velocity集成。 我的服务器进入无限循环。 服务器的控制台读取是: 我已将循环的开头标记为“ - >”。
--> at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)
at org.apache.jsp.WEB_002dINF.views.layout_jsp._jspx_meth_tiles_005finsertAttribute_005f0(layout_jsp.java:102)
at org.apache.jsp.WEB_002dINF.views.layout_jsp._jspService(layout_jsp.java:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:684)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:678)
at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
at org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:690)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
at org.apache.tiles.renderer.impl.DefinitionAttributeRenderer.write(DefinitionAttributeRenderer.java:56)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer.write(ChainedDelegateAttributeRenderer.java:76)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:336)
at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:210)
at org.apache.tiles.template.InsertAttributeModel.end(InsertAttributeModel.java:126)
--> at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)
at org.apache.jsp.WEB_002dINF.views.layout_jsp._jspx_meth_tiles_005finsertAttribute_005f0(layout_jsp.java:102)
at org.apache.jsp.WEB_002dINF.views.layout_jsp._jspService(layout_jsp.java:69)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:684)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:678)
at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
at org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:690)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
at org.apache.tiles.renderer.impl.DefinitionAttributeRenderer.write(DefinitionAttributeRenderer.java:56)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer.write(ChainedDelegateAttributeRenderer.java:76)
at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:336)
at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:210)
at org.apache.tiles.template.InsertAttributeModel.end(InsertAttributeModel.java:126)
at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)
--> at org.apache.jsp.WEB_002dINF.views.layout_jsp._jspx_meth_tiles_005finsertAttribute_005f0(layout_jsp.java:102)
AND SO ON...
我的servlet-context.xml
中有以下代码<beans:bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
<beans:property name="order" value="0"/>
</beans:bean>
<beans:bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<beans:property name="resourceLoaderPath" value="/WEB-INF/views/" />
</beans:bean>
<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<beans:property name="cache" value="true"/>
<beans:property name="prefix" value=""/>
<beans:property name="suffix" value=".vm"/>
<beans:property name="order" value="2"/>
</beans:bean>
<beans:bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/tiles.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
我的WEB-INF / views / layout.jsp是
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ 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=ISO-8859-1">
<title><tiles:insertAttribute name="title"/> </title>
</head>
<body>
<tiles:insertAttribute name="body"/>
</body>
</html>
最后我的速度文件home.vm是:
<html>
<body>
<h1>
Hello world!
</h1>
##This is comment
<P> The time on the server is ${serverTime}. </P>
</body>
</html>
tiles.xml:
<tiles-definitions>
<definition name="base.definition" template="/WEB-INF/views/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="body" value="" />
</definition>
<definition name="home" extends="base.definition">
<put-attribute name="title" value="home" />
<put-attribute name="body" value="/WEB-INF/views/home.vm" />
</definition>
<tiles-definitions>
我读过,你可以使用多个视图解析器来指定顺序。 所以我指定了视图解析器的顺序。
我对这项技术很陌生。请帮忙。 提前谢谢。
答案 0 :(得分:1)
由于您将属性“title”设置为与定义名称相同的值,因此会导致错误。瓷砖可以使用嵌套;在案例中的标题,重定向到自己导致循环。 一个简单的解决方法是将标题值更改为不是定义名称的内容。
更改
<put-attribute name="title" value="home" />
到
<put-attribute name="title" value="home page" />
-
<tiles-definitions>
<definition name="base.definition" template="/WEB-INF/views/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="body" value="" />
</definition>
<definition name="home" extends="base.definition">
<put-attribute name="title" value="home page" />
<put-attribute name="body" value="/WEB-INF/views/home.vm" />
</definition>
<tiles-definitions>
答案 1 :(得分:0)
尝试添加
</tiles-definitions>
tiles.xml
结尾。
答案 2 :(得分:0)
修改你的tiles.xml如下template="WEB-INF/views/layout.jsp"
它为我解决了无限循环问题,但仍然存在一些问题。如果你解决它也帮帮我
答案 3 :(得分:0)
我一般是Tiles和Spring的新手,在定义我的tiles.xml文件时遇到了同样的问题。
在此回答上述发布的解决方案和我自己的经验,以阐述我面临的问题:
问题在于属性的值
<definition name="welcome" .. >
。
我放置了movies
&#39;作为标题和标题属性的值。但是,&#39; movies
&#39;不应该被用作值,因为它被用作定义。
更改&#39; movie
&#39;对于其他一些价值(&#34;我的电影回家&#34;),它运作良好。
我的错误(堆栈溢出)导致代码:
<definition name="welcome" extends="baseLayout">
<put-attribute name="title" value="movies" />
<put-attribute name="heading" value="movies" />
<put-attribute name="tagline" value="Welcome to Movie Store" />
<put-attribute name="content" value="/WEB-INF/views/movies.jsp" />
</definition>
<definition name="movies" extends="baseLayout">
<put-attribute name="title" value="Movies list" />
<put-attribute name="heading" value="Movies List" />
<put-attribute name="tagline" value="Available Products" />
<put-attribute name="content" value="/WEB-INF/views/movies.jsp" />
</definition>
以下是问题的解决方案:
<definition name="welcome" extends="baseLayout">
<put-attribute name="title" value="My Movies Home" />
<put-attribute name="heading" value="My Movies Home" />
<put-attribute name="tagline" value="Welcome to Movie Store" />
<put-attribute name="content" value="/WEB-INF/views/movies.jsp" />
</definition>
<definition name="movies" extends="baseLayout">
<put-attribute name="title" value="Movies list" />
<put-attribute name="heading" value="Movies List" />
<put-attribute name="tagline" value="Available Products" />
<put-attribute name="content" value="/WEB-INF/views/movies.jsp" />
</definition>