Server goes into infinite loop while implementing Tiles with Velocity

爱⌒轻易说出口 提交于 2019-12-12 02:53:58

问题


EDIT: I am trying to integrate Tiles with Velocity using spring MVC. My server is going into infinite loop. The console reading of server is: I have marked the start of the loop as "-->".

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

I have the following code in my 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>

My WEB-INF/views/layout.jsp is

<%@ 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>

and finally my velocity file home.vm is:

<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>

I read that, you can use multiple view resolver with specifying the order. SO I specified the order of the view resolver.

I am pretty new to this technology. Please help. Thanks in advance.


回答1:


Try adding

</tiles-definitions>

At the end of tiles.xml.




回答2:


The error is caused becuase you have the attribute 'title' set with the same value as the definition name. Tiles can use nesting; the title in the case, redirects to itself causing the loop. A simple fix is to change the title value to something that is not a name of a definition.

change

<put-attribute name="title" value="home" />

to

<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>



回答3:


modify your tiles.xml as followingtemplate="WEB-INF/views/layout.jsp" it solves infinite loop problem for me but still some problems. Help me also if you fix it




回答4:


I am newbie to Tiles and Spring in general and had the same issue when defining my tiles.xml file.

Answering hereby with the posted solution above and my own experience to elaborate the issue I faced:

The problem was in the values for the attributes of <definition name="welcome" .. > .

I placed 'movies' as values to the title and heading attributes. But, 'movies' should not have been used as a value since it is used as a definition.

When changing 'movie' to some other value ("My movies home"), it worked fine.

My Error (stack overflow) causing code:

<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>

The following is the solution to the problem:

<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>


来源:https://stackoverflow.com/questions/15781574/server-goes-into-infinite-loop-while-implementing-tiles-with-velocity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!