如何避免在java自定义标记处理程序中生成html? [英] How do i avoid generating html in a java custom tag handler?
本文介绍了如何避免在java自定义标记处理程序中生成html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能找到的每个例子都有标签处理程序java类生成html并用 out.print(someHTML)喷出来;
Every example i can find has the tag handler java class generating html and spewing it out with out.print(someHTML);
有没有办法在请求中包含一个jsp并添加属性?
Is there a way to include a jsp and add attributes to the request instead?
推荐答案
我没有'尝试过这个但是应该可以通过从Request对象获取RequestDispatcher :
I haven't tried this but it should be possible by obtaining a RequestDispatcher from the Request object:
public int doStartTag() throws JspException {
try {
pageContext.setAttribute("title", "My Title");
pageContext.getRequest().getRequestDispatcher("/WEB-INF/includes/header.jspf").include(pageContext.getRequest(), pageContext.getResponse());
}
catch (IOException e) {
}
return EVAL_BODY_INCLUDE;
}
PageContext还有包含方法,但这似乎只适用于静态文件,而不是jsps。
The PageContext also has an include method but that seems to only work for static files, not jsps.
这篇关于如何避免在java自定义标记处理程序中生成html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文