小编典典

如何从Apache Tiles模板引用属性列表

jsp

我试图在基本模板中定义一个属性列表,其中包括所有css链接,并且子定义将根据需要附加其他css链接。我在磁贴定义配置文件中定义了该列表,并尝试在template.jsp文件中使用该列表,但是出现以下错误:

org.apache.tiles.template.NoSuchAttributeException:导入属性时出错。属性“链接”为空

磁贴定义文件:

    <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC 
        "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" 
        "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">       
<tiles-definitions>
    <definition name="master.template"
        template="/WEB-INF/tiles/templates/template.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/WEB-INF/tiles/templates/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/tiles/templates/menu.jsp" />
        <put-attribute name="body" value="/WEB-INF/views/home.jsp" />
        <put-attribute name="footer" value="/WEB-INF/tiles/templates/footer.jsp" />         
        <put-list-attribute name="links" inherit="true" cascade="true">
            <add-attribute type="string" value="/stles/default.css" />
            <add-attribute type="string" value="/styles/another.css" />
        </put-list-attribute>
    </definition>
    <definition name="home" extends="master.template">
        <put-attribute name="title" value="Welcome Home" />
        <put-attribute name="body" value="/WEB-INF/views/home.jsp" />
    </definition>    
    <definition name="about" extends="master.template">
        <put-attribute name="title" value="About" />
        <put-attribute name="body" value="/WEB-INF/views/about.jsp" />

    </definition> 
</tiles-definitions>

Template.jsp

<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>    
        <title><tiles:insertAttribute name="title" ignore="true" /></title>         
        <!-- links -->      
        <tiles:useAttribute name="links"/>  
        <c:forEach var="href" items="${items}"> 
        <link type="text/css" rel="stylesheet" href="${href}" />
        </c:forEach>                    
    </head>
    <body>
        <div id="page">
            <div id="header"><tiles:insertAttribute name="header" /></div>
            <div id="menu"><tiles:insertAttribute name="menu" /></div>          
            <div id="body"><tiles:insertAttribute name="body" /></div>
            <div id="footer"><tiles:insertAttribute name="footer" /></div>
        </div>
    </body>
</html>

HTTP错误500

问题访问/。原因:

ServletException including path '/WEB-INF/tiles/templates/template.jsp'.

造成原因:

org.apache.tiles.impl.CannotRenderException:ServletException,包括路径“ /WEB-
INF/tiles/templates/template.jsp”。在org.apache.tiles.impl.BasicTilesContainer的org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:692)处(BasicTilesContainer.java:627)在org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)在org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)在org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1031)上的org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)在org.springframework.web.servlet.DispatcherServlet上。在org.mortbay.thread.QueuedThreadPool
$
PoolThread.run(QueuedThreadPool.java:582)处运行(SelectChannelEndPoint.java:409)原因:org.apache.tiles.util.TilesIOException:ServletException包括路径’/
WEB-INF / tiles
/templates/template.jsp”。在org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:243)在org.apache.tiles.servlet.context.ServletUtil.wrapServletException(ServletUtil.java:241)在org.apache.tiles.servlet
org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)处的.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer
.java:106),网址为org.apache.tiles.impl。org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:690)处的BasicTilesContainer.render(BasicTilesContainer.java:670)…
37更多原因:org.apache.tiles.template.NoSuchAttributeException:导入属性时出错。属性``links’‘在org.apache.tiles的org.apache.tiles.template.ImportAttributeModel.getImportedAttributes(ImportAttributeModel.java:78)的org.apache.tiles.template.ImportAttributeModel.importSingleAttribute(ImportAttributeModel.java:133)为null
org.apache.jsp.WEB_002dINF.tiles.templates.template_jsp._jspService(template_jsp.java:110)上的.jsp.taglib.UseAttributeTag.doTag(UseAttributeTag.java:175)在org.apache.jasper.runtime.HttpJspBase.service
(HttpJspBase.java:97),位于org.apache的javax.servlet.http.HttpServlet.service(HttpServlet.java:717)。

造成原因:

org.apache.tiles.util.TilesIOException:ServletException,包括路径“ /WEB-
INF/tiles/templates/template.jsp”。在org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:243)在org.apache.tiles.servlet.context.ServletUtil.wrapServletException(ServletUtil.java:241)在org.apache.tiles.servlet
org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)处的.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)在org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer
.java:106)在org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)在org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:

造成原因:

org.apache.tiles.template.NoSuchAttributeException:导入属性时出错。在org.apache.tiles的org.apache.tiles.template.ImportAttributeModel.getImportedAttributes(ImportAttributeModel.java:78)的org.apache.tiles.template.ImportAttributeModel.importSingleAttribute(ImportAttributeModel.java:133)处属性’links’为空org.apache.jsp.WEB_002dINF.tiles.templates.template_jsp._jspService(template_jsp.java:110)上的.jsp.taglib.UseAttributeTag.doTag(UseAttributeTag.java:175)在org.apache.jasper.runtime.HttpJspBase.service
(HttpJspBase.java:97),位于org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377),位于javax.servlet.http.HttpServlet.service(HttpServlet.java:717)。
org.apache上的servlet.JspServlet.serviceJspFile(JspServlet.java:313)。


阅读 438

收藏
2020-06-10

共1个答案

小编典典

我认为存在一个问题:Inherited =“ true”属性。由于您没有扩展定义,因此请尝试将其删除并查看它是否有效。

2020-06-10