Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to include page from custom tags

 
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
 
This guy is skipping without a rope. At least, that's what this tiny ad said:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic