[英]How to include a jsp file using a custom taglib?
我正在嘗試使用自定義 taglib 包含一個 jsp 文件。 我有所有的 taglib 設置,但它顯示了 include 語句而不是 jsp 內容。
public int doStartTag() throws JspException {
JspWriter out = pageContext.getOut();
StringBuffer sb = new StringBuffer();
if (section != null && !section.isEmpty()) {
sb.append("<%@ include file=\"defaultHeader.jsp\" %>");
}
try {
out.println(sb.toString());
} catch (IOException e) {
log.error("Failed to generate the tag", e);
e.printStackTrace();
}
return super.doStartTag();
我對 taglibs 真的很陌生,所以感謝任何幫助。 謝謝
您可以使用PageContext中的文件名設置一個屬性,然后在 JSP 中創建包含指令
像這樣的東西
pageContext.setAttribute("includeFileName", "YourFile.jsp path", PageContext.REQUEST_SCOPE);
您的 JSP:
<%@include file="${pageContext.includeFileName}" %>
然后在您的 JSP 中,獲取該屬性和 voula! 你真的不需要在編寫器中添加或寫入孔 JSP 文件
希望能幫助到你 :)
我想出了使用 pageContext :
pageContext.include(ERROR_BLOCK_FILE_NAME);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.