我正在尝试在我的 tiles.xml 文件中使用带有 Regexp 前缀的 Spring MVC 3.2.4 和 Tiles 3.0.1。我是 Tiles 的新手,所以我可能做错了什么,但我一直在尝试遵循我在 Tiles 文档网站上阅读的内容以及应用来自 tech.finn.no 博客的内容。
不幸的是,当我在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>
瓷砖.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>
默认.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>
我认为这个配置没有什么特别之处,所以我不确定为什么我会陷入无限循环。如果我将 CompleteAutoTilesInitializer 类替换为 BasicTilesInitializerClass 并改用通配符(即:/)并将 {1} 替换为 {1}/{2},则视图会正确加载(无无限循环)。
任何想法我做错了什么,或者这是一个瓷砖问题?