You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rw...@us.britannica.com on 2000/03/03 13:38:21 UTC

TagLibs, Dynamic Content, and jsp:include (grabbing JSP output)

I've been working on a simple tag extension that performs a transformation
of an XML document based upon an XSLT stylesheet.  The  syntax I'm shooting
for is this:

  <%@ taglib uri="xslt-taglib" prefix="xslt" %> 
  <xslt:transform> 
   <xslt:doc> 
     ...an arbitrary XML document... 
   </xslt:doc> 
   <xslt:style> 
     ...an arbitrary XSLT stylesheet... 
   </xslt:style> 
  </xslt:transform> 

This works fine as long as I've got hard-coded <doc> and <style> bodies.
But what I'd really like to do is this: 

   <xslt:transform> 
    <xslt:doc> 
     <jsp:include page="view.jsp" flush="true" /> 
    </xslt:doc> 
    <xslt:style> 
     <jsp:include page="presentation.jsp" flush="true" /> 
    </xslt:style> 
   </xslt:transform> 

where view.jsp and presentation.jsp use the implictly passed request and
session parameters to generate the appropriate documents.  This fails, of
course, with a message stating that you can't flush the buffer inside a
custom tag.  This is the correct behavior, according to the 1.1 beta spec: 

 "It is not possible to invoke flush on a BodyContent object, as there is
 no *backing* stream. This means that it is not legal to do a jsp:include
 when out is not bound to the top-level JspWriter." [Section 5.4.5]

But I wonder if there is some workaround (perhaps by clever manipulations of
BodyContent objects?) or another way to accomplish similar behaviour.  More
generally, is there some way to grab the output of a <jsp:include> or <%@
include %> tag rather than having it write directly to the servlet output
stream?  (Or more to the point, to grab the output of a JSP invocation?) It
would be *really* nice (and really powerful) to be able to pass content
dynamically generated by a JSP to beans and custom tags.  (I know I could
always submit an HTTP request and read the output, but then I lose the
implict passing of request attributes, and I suspect there is a performance
hit since I'd have to go through the web server again.)

Any ideas? 
 - Rod 

(PS: my apologizes if you saw this on the tomcat-general list, I didn't get
much of a response there so I thought I'd try here.)