我正在尝试使用自定义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();
我对Taglib真的很陌生,因此可以提供任何帮助。谢谢
最佳答案
您可以在PageContext中使用文件名设置属性,然后在JSP中创建include指令。
像这样
pageContext.setAttribute("includeFileName", "YourFile.jsp path", PageContext.REQUEST_SCOPE);
您的JSP:
<%@include file="${pageContext.includeFileName}" %>
然后在您的JSP中,获取该属性和内容!
您实际上不需要在编写器中添加或写入漏洞JSP文件。
希望能帮助到你 :)