我正在使用Tiles 3为我的Spring网站制作模板。 layout.jsp结合了header.jsp,body和footer.jsp。 在header.jsp中,我有一个我想通过tile定义文件(tiles.xml)中的put-attribute将标题传递给index.jsp。但是当我运行index.jsp时,我得到了
org.apache.tiles.template.NoSuchAttributeException: Attribute 'title' not found
以下是我的代码:
tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="base.definition" template="/WEB-INF/jsp/layout.jsp">
<put-attribute name="header" value="/WEB-INF/jsp/header.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" />
</definition>
<definition name="contact" extends="base.definition">
<put-attribute name="title" value="Contact Manager" />
<put-attribute name="body" value="/WEB-INF/jsp/contact.jsp" />
<put-attribute name="Contact" value="Home" />
</definition>
<definition name="index" extends="base.definition">
<put-attribute name="title" value="Hello Spring MVC" />
<put-attribute name="body" value="/WEB-INF/jsp/index.jsp" />
<put-attribute name="page_header" value="Home" />
</definition>
<definition name="case-list" extends="base.definition">
<put-attribute name="title" value="Case list" />
<put-attribute name="body" value="/WEB-INF/jsp/case/list.jsp" />
<put-attribute name="page_header" value="Case list" />
</definition>
</tiles-definitions>
layout.jsp
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="body" />
<tiles:insertAttribute name="footer" />
header.jsp中
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>
<tiles:insertAttribute name="title"></tiles:insertAttribute>
</title>
</head>
<body>
...
的index.jsp
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<h1>This is index</h1>
When I try to run index.jsp
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.tiles.request.render.CannotRenderException: An exception occurred processing JSP page [/WEB-INF/jsp/layout.jsp] at line [2]
1: <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
2: <tiles:insertAttribute name="header" />
3: <tiles:insertAttribute name="body" />
4: <tiles:insertAttribute name="footer" />
5:
Stacktrace:
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
org.apache.tiles.request.render.CannotRenderException: An exception occurred processing JSP page [/WEB-INF/jsp/layout.jsp] at line [2]
1: <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
2: <tiles:insertAttribute name="header" />
3: <tiles:insertAttribute name="body" />
4: <tiles:insertAttribute name="footer" />
5:
错误堆栈跟踪
Stacktrace:
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:399)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:221)
org.apache.tiles.renderer.DefinitionRenderer.render(DefinitionRenderer.java:59)
org.springframework.web.servlet.view.tiles3.TilesView.renderMergedOutputModel(TilesView.java:132)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1282)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
java.io.IOException: An exception occurred processing JSP page [/WEB-INF/jsp/layout.jsp] at line [2]
1: <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
2: <tiles:insertAttribute name="header" />
3: <tiles:insertAttribute name="body" />
4: <tiles:insertAttribute name="footer" />
5:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:471)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.tiles.request.servlet.ServletRequest.forward(ServletRequest.java:265)
org.apache.tiles.request.servlet.ServletRequest.doForward(ServletRequest.java:228)
org.apache.tiles.request.AbstractClientRequest.dispatch(AbstractClientRequest.java:57)
org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:47)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:397)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:221)
org.apache.tiles.renderer.DefinitionRenderer.render(DefinitionRenderer.java:59)
org.springframework.web.servlet.view.tiles3.TilesView.renderMergedOutputModel(TilesView.java:132)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1282)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
java.io.IOException: JSPException including path '/WEB-INF/jsp/header.jsp'.
org.apache.tiles.request.servlet.ServletUtil.wrapServletException(ServletUtil.java:61)
org.apache.tiles.request.jsp.JspRequest.doInclude(JspRequest.java:125)
org.apache.tiles.request.AbstractViewRequest.dispatch(AbstractViewRequest.java:47)
org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:47)
org.apache.tiles.request.render.ChainedDelegateRenderer.render(ChainedDelegateRenderer.java:68)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:188)
org.apache.tiles.template.InsertAttributeModel.execute(InsertAttributeModel.java:132)
org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:299)
org.apache.jsp.WEB_002dINF.jsp.layout_jsp._jspx_meth_tiles_005finsertAttribute_005f0(layout_jsp.java:160)
org.apache.jsp.WEB_002dINF.jsp.layout_jsp._jspService(layout_jsp.java:117)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.tiles.request.servlet.ServletRequest.forward(ServletRequest.java:265)
org.apache.tiles.request.servlet.ServletRequest.doForward(ServletRequest.java:228)
org.apache.tiles.request.AbstractClientRequest.dispatch(AbstractClientRequest.java:57)
org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:47)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:397)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:221)
org.apache.tiles.renderer.DefinitionRenderer.render(DefinitionRenderer.java:59)
org.springframework.web.servlet.view.tiles3.TilesView.renderMergedOutputModel(TilesView.java:132)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1282)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
org.apache.tiles.template.NoSuchAttributeException: Attribute 'title' not found.
org.apache.tiles.template.DefaultAttributeResolver.computeAttribute(DefaultAttributeResolver.java:50)
org.apache.tiles.template.InsertAttributeModel.resolveAttribute(InsertAttributeModel.java:165)
org.apache.tiles.template.InsertAttributeModel.execute(InsertAttributeModel.java:121)
org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:299)
org.apache.jsp.WEB_002dINF.jsp.header_jsp._jspx_meth_tiles_005finsertAttribute_005f0(header_jsp.java:550)
org.apache.jsp.WEB_002dINF.jsp.header_jsp._jspService(header_jsp.java:134)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:895)
org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:679)
org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:673)
org.apache.tiles.request.jsp.JspRequest.doInclude(JspRequest.java:123)
org.apache.tiles.request.AbstractViewRequest.dispatch(AbstractViewRequest.java:47)
org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:47)
org.apache.tiles.request.render.ChainedDelegateRenderer.render(ChainedDelegateRenderer.java:68)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:188)
org.apache.tiles.template.InsertAttributeModel.execute(InsertAttributeModel.java:132)
org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:299)
org.apache.jsp.WEB_002dINF.jsp.layout_jsp._jspx_meth_tiles_005finsertAttribute_005f0(layout_jsp.java:160)
org.apache.jsp.WEB_002dINF.jsp.layout_jsp._jspService(layout_jsp.java:117)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.tiles.request.servlet.ServletRequest.forward(ServletRequest.java:265)
org.apache.tiles.request.servlet.ServletRequest.doForward(ServletRequest.java:228)
org.apache.tiles.request.AbstractClientRequest.dispatch(AbstractClientRequest.java:57)
org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:47)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:397)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:221)
org.apache.tiles.renderer.DefinitionRenderer.render(DefinitionRenderer.java:59)
org.springframework.web.servlet.view.tiles3.TilesView.renderMergedOutputModel(TilesView.java:132)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1282)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我做错了什么?
答案 0 :(得分:0)
根据您的图块定义,
<tiles:insertAttribute name="{attribute-name}" />
只能在
中使用 template="/WEB-INF/jsp/layout.jsp"
在尝试使用header.jsp时,它失败了。更新代码以使用layout.jsp并将其从其他JSP文件中删除。