Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to include page from custom tags

 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I'm repharsing my last problem)
How to include a jsp page/servlet mapping from a custom tag?
I have tried requestdispatcher.include(request, response), and the page's output does not display on the correct position on the HTML page.
I've tried pageContext.include("servletmapping"); and I got an exception thrown. Something about illegal to flush from within a Custom Tag.
Chu
 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like its impossible to include another page from nested tags of BodyTagSupport.
Here's a work around that I've found.
<%
pageContext.setAttribute("jspWriter",out);
%>
<ct:servletList default="/WEB-INF/props.list">
html
<ct:aServlet/>
more html
</ct:servletList>
// aServletTag class
public int doStartTag() throws JspException {
flushParentBodyContent();
// Do dispatcher include
}
protected void flushParentBodyContent() throws JspException{
Tag parent=getParent();
if(parent != null && parent instanceof BodyTagSupport){
BodyTagSupport parentBodyTag=(BodyTagSupport)parent;
BodyContent parentBodyContent = parentBodyTag.getBodyContent();
try {
JspWriter writer = (JspWriter) pageContext.getAttribute("jspWriter");
parentBodyContent.writeOut(writer);
writer.flush();
} catch (IOException e) {
throw new JspException("IterationTag: " +e.getMessage());
}
parentBodyContent.clearBody();
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic