2013-10-25 56 views
1

我試圖使用Spring MVC 3.2.4 &瓷磚3.0.1與我的tiles.xml文件中的正則表達式前綴。我是Tiles的新手,所以我可能會做錯事,但一直試圖遵循我在Tiles doc站點上閱讀過的內容以及應用tech.finn.no博客中的內容。Spring 3.2.4 + Tiles 3 =解析視圖時的無限循環?

不幸的是,當我在我的tiles.xml文件中使用帶有RegExp前綴的completeAutoLoad = true時,在嘗試解析視圖時,我陷入了無限循環。

堆棧跟蹤:

SEVERE: Servlet.service() for servlet jsp threw exception 
java.lang.StackOverflowError 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 

.... 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapper.encodeURL(SaveContextOnUpdateOrErrorResponseWrapper.java:181) 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 

.... 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76) 
    at org.springframework.web.servlet.tags.UrlTag.createUrl(UrlTag.java:227) 
    at org.springframework.web.servlet.tags.UrlTag.doEndTag(UrlTag.java:174) 
    at org.apache.jsp.tag.webutil.load_002dscripts_tag._jspx_meth_spring_005furl_005f0(load_002dscripts_tag.java:300) 
    at org.apache.jsp.tag.webutil.load_002dscripts_tag.doTag(load_002dscripts_tag.java:113) 
    at org.apache.jsp.WEB_002dINF.views.tiles.layouts.default_jsp._jspx_meth_util_005fload_002dscripts_005f0(default_jsp.java:176) 
    at org.apache.jsp.WEB_002dINF.views.tiles.layouts.default_jsp._jspService(default_jsp.java:93) 
    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) 

的pom.xml:

<dependency> 
     <groupId>org.apache.tiles</groupId> 
     <artifactId>tiles-extras</artifactId> 
     <version>3.0.1</version> 
    </dependency> 

webmvc-config.xml中:

<bean class="org.springframework.web.servlet.view.tiles3.SpringWildcardServletTilesApplicationContext" autowire="constructor" /> 
<bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver" > 
    <property name="cache" value="false"/> 
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" /> 
</bean> 

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> 
<property name="completeAutoload" value="true"/> 
</bean> 

Tiles.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"> 
<tiles-definitions> 
<definition name="REGEXP:(.+)" template="/WEB-INF/views/tiles/layouts/default.jsp"> 
    <put-attribute name="meta" value="/WEB-INF/views/tiles/{1}/meta.jsp"/> 
    <put-attribute name="head" value="/WEB-INF/views/tiles/{1}/head.jsp"/> 
    <put-attribute name="header" value="/WEB-INF/views/tiles/{1}/header.jsp"/> 
    <put-attribute name="menu" value="/WEB-INF/views/tiles/{1}/menu.jsp"/> 
    <put-attribute name="body" value="/WEB-INF/views/tiles/{1}/body.jsp"/> 
    <put-attribute name="footer" value="/WEB-INF/views/tiles/{1}/footer.jsp"/> 
</definition> 

</tiles-definitions> 

的Default.jsp:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<%@ taglib prefix="util" tagdir="/WEB-INF/tags/util"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
    <jsp:directive.page contentType="text/html;charset=UTF-8" /> 
    <jsp:directive.page pageEncoding="UTF-8" /> 

    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <meta http-equiv="X-UA-Compatible" content="IE=8" />  
     <tiles:insertAttribute name="meta" ignore="true" /> 

     <util:load-scripts /> 

     <tiles:insertAttribute name="head" ignore="true" /> 

     <spring:message code="application_name" var="app_name" htmlEscape="false"/> 
     <title><spring:message code="welcome_h3" arguments="${app_name}" /></title> 
    </head> 

    <body class="tundra spring"> 
     <div id="wrapper"> 
      <div id="header"><tiles:insertAttribute name="header" ignore="true" /></div> 
      <div id="menu"><tiles:insertAttribute name="menu" ignore="true" /></div> 
      <div id="main"> 
       <div id="body"><tiles:insertAttribute name="body"/></div> 
       <div id="footer"><tiles:insertAttribute name="footer" ignore="true"/></div> 
      </div> 
     </div> 
    </body> 
</html> 

/WEB-INF/views/tiles/secure/login/body.jsp:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 
<%@ taglib prefix="util" tagdir="/WEB-INF/tags/util"%> 

<jsp:directive.page contentType="text/html;charset=UTF-8" /> 

<div class="container"> 

<form name="login" class="form-signin" action='<spring:url value="/j_spring_security_check"/>' method="POST"> 
    <h2 class="form-signin-heading">Please sign in</h2> 
    <input type="text" class="form-control" name="j_username" placeholder="Email address" autofocus> 
    <input type="password" class="form-control" name="j_password" placeholder="Password"> 
    <label class="checkbox"> <input type="checkbox" value="remember-me"> Remember me</label> 
    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button> 
</form> 
</div> 

我不覺得有什麼在這種配置專門的特殊,所以我不確定爲什麼我會陷入無限循環。如果我使用BasicTilesInitializerClass替換CompleteAutoTilesInitializer類並使用通配符(即:/),並用{1}/{2}替換{1},則視圖會正確加載(無限循環)。

任何想法我做錯了,或者這是一個瓷磚問題?

回答

2

研究發現,指出,正則表達式是過於貪婪,並試圖以匹配所有屬性永遠爲好,因此造成的StackOverflow類似SO問題(https://stackoverflow.com/a/6617343/827480)。目前的解決方法是使用不太貪婪的正則表達式。