0

编辑: 我正在尝试使用 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>

瓷砖.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>

我读到了,您可以使用多视图解析器来指定顺序。所以我指定了视图解析器的顺序。

我对这项技术很陌生。请帮忙。提前致谢。

4

4 回答 4

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>
于 2014-07-31T08:56:31.730 回答
0

尝试添加

</tiles-definitions>

在结束时tiles.xml

于 2013-04-03T07:43:20.023 回答
0

修改您的tiles.xml,如下所示template="WEB-INF/views/layout.jsp",它为我解决了无限循环问题,但仍然存在一些问题。如果你修复它也帮助我

于 2013-08-17T11:53:49.300 回答
0

一般来说,我是 Tiles 和 Spring 的新手,在定义我的 tiles.xml 文件时遇到了同样的问题。

特此回答上面发布的解决方案和我自己的经验来详细说明我面临的问题:

问题在于 的属性值<definition name="welcome" .. >

我将“ movies”作为标题和标题属性的值。但是,' movies' 不应该被用作值,因为它被用作定义。

将 ' movie' 更改为其他值(“我的电影之家”)时,效果很好。

我的错误(堆栈溢出)导致代码:

<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>
于 2016-05-28T02:59:28.210 回答