2014-09-30 43 views
2

我設計一個JSP的模板,就像@Will哈同很好的例子(Link),我有genericpage.tag傳遞JSP屬性爲嵌套JSTL標記

<%@tag description="Overall Page template" pageEncoding="UTF-8"%> 
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %> 
<%@attribute name="header" fragment="true" %> 
<%@attribute name="footer" fragment="true" %> 
<html> 
    <body> 
    <div id="pageheader"> 
     <jsp:invoke fragment="header"/> 
    </div> 
    <div id="body"> 
     <jsp:doBody/> 
    </div> 
    <t:page.footer> 
     <jsp:invoke fragment="footer"/> 
    </t:page.footer>      
    </body> 
</html> 

,當你看到我定義page.footer.taggenericpage.tag與此內容:

page.footer.tag:

<%@attribute name="footer" fragment="true" %> 
<div id="footer"> 
    <jsp:invoke fragment="footer"/> 
</div> 
在我的JSP頁面

我有:

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %> 
<t:genericpage> 
    <jsp:attribute name="header"> 
     <h1>Welcome</h1> 
    </jsp:attribute> 
    <jsp:attribute name="footer"> 
     <p id="copyright">Copyright 1927, Future Bits When There Be Bits Inc.</p> 
    </jsp:attribute> 
    <jsp:body> 
     <p>Some Content</p>   
    </jsp:body> 
</t:genericpage> 

屬性是做工精細,但當我發送頁腳屬性爲其他標籤頁面(page.footer.tag)它不起作用

另一方面,頁眉和頁腳屬性工作正常,當我在genericpage.tag但他們犯規像page.footer.tag我使用到genericpage.tag

回答

0

,你也可以做這樣的事情在neasted標籤的工作。 在你的本金JSP u需要把這個代碼:

< JSP:包括頁= 「example.jsp」>

example.jsp:

<%@頁面的contentType =「text/html的;字符集= windows-1252「%>

和您的代碼..

+0

這是如何解決OP的問題? – 2014-10-29 23:33:21