包含带有自定义标签的 jspf 文件
如何通过自定义标签将jspf文件添加到jsp页面?
在标签支持类中,我可以使用...添加jspf代码。
JspWriter writter = this.pageContext.getOut();
writter.append( "html code");
但是我该怎么做才能添加文件呢?
How can I add jspf file to jsp page via custom tag?
In the tag support class I can add code of jspf using....
JspWriter writter = this.pageContext.getOut();
writter.append( "html code");
But what shall I do to add file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果“jspf 文件”指的是在静态包含中引用的 JSP 片段(例如
<%@ include file="fragment.jspf" %>
),则不能。原因是静态包含是在 JSP 编译之前处理的,而标记库是在编译之后处理的。
相反,如果您指的是动态包含(通常通过
调用),那么您可以通过请求调度程序从标记处理程序执行此操作。您始终可以将静态包含包装在实现某些条件逻辑的标记处理程序中。这将控制该片段的输出是否插入到渲染的页面中。然而,它仍然会被编译到页面中,我怀疑您的目标是减少 JSP 的整体大小,在这种情况下您就不走运了。
If by "jspf file" you mean a JSP fragment that you reference in a static include (eg,
<%@ include file="fragment.jspf" %>
), you can't.The reason is that static includes are processed before the JSP is compiled, while tag libraries are processed afterward.
If, instead, you mean a dynamic include (normally invoked via
<jsp:include>
), then you can do this from a tag handler via the request dispatcher.You could always wrap the static include in a tag handler that implements some conditional logic. This would control whether the output of that fragment is inserted into the rendered page. However, it would still be compiled into the page, and I suspect that your goal is to reduce the overall size of your JSPs, in which case you're out of luck.