2016-05-01 88 views
0

我正在嘗試爲佈局目的創建我的jsp自定義標籤。JSP自定義標籤 - 片段屬性不起作用

我創建panelLayout.tag文件中像

<%@ tag language="java" pageEncoding="ISO-8859-1"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 

<%@ attribute name="heading" required="false" %> 
<%@ attribute name="footer" fragment="true"%> 

<div class="panel panel-default"> 

    <c:if test="${not empty heading}"> 
     <div class="panel-heading"> 
      <c:out value="${heading}"></c:out> 
     </div> 
    </c:if> 

    <div class="panel-body">  
     <jsp:doBody/>        
    </div> 

    <div class="panel-footer"> 
     <jsp:invoke fragment="footer"/> 
    </div> 
</div> 

,我使用它在JSP中的一個,如下

<%@taglib prefix="t" tagdir="/WEB-INF/tags" %> 

<t:panelLayout> 
    This is my body        
    <jsp:attribute name="footer"> 
     This is my footer 
    </jsp:attribute> 
</t:panelLayout> 

而且我得到以下錯誤

org.apache.jasper.JasperException: /WEB-INF/pages/Groups.jsp (line: 86, column: 33) jsp:attribute must be the subelement of a standard or custom action 
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42) 
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443) 
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:89) 
    org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1126) 
    org.apache.jasper.compiler.Parser.parseElementsScriptless(Parser.java:1499) 
    org.apache.jasper.compiler.Parser.parseBody(Parser.java:1666) 
    org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:986) 
    org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1258) 
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1451) 
    org.apache.jasper.compiler.Parser.parse(Parser.java:138) 
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242) 
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:102) 
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:374) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:354) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:341) 
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) 
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263) 
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208) 
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992) 
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939) 
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) 
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624) 
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.64 logs. 

如果我刪除頁腳片段,它工作正常。

我從這裏 https://docs.oracle.com/cd/E19879-01/819-3669/bnamr/index.html

搜索計算器和其他參考了參考爲好,但找不到我做錯了什麼。

任何幫助表示讚賞。

+0

你的標籤處理程序類在哪裏? PLZ與tld文件共享 –

回答

0

你可以嘗試包圍<jsp:body></jsp:body>之間的身體:

<t:panelLayout> 
    <jsp:attribute name="footer"> 
     This is my footer 
    </jsp:attribute> 
    <jsp:body> 
     This is my body 
    </jsp:body> 
</t:panelLayout> 

檢查The Java EE 5 Tutorial - Types of Tags

的jsp:body元素

您也可以明確地指定一個簡單的標籤的正文使用jsp:body元素。如果使用jsp:attribute元素指定了一個或多個屬性,則jsp:body是指定標籤正文的唯一方法。如果一個或多個jsp:attribute元素出現在標籤調用的主體中,但不包含jsp:body元素,則該標籤具有空的主體。

相關問題