tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre Delisle <pierre.deli...@sun.com>
Subject Re: Using a jsp:include action (JSP 1.1) within a BodyTag taglib tag
Date Tue, 30 Jan 2001 20:06:38 GMT
> I've looked through the JSP 1.2 spec (although not completely), and I
> did not see any mention of this type of restriction.  Is this correct?
> 
> I realize that this is somewhat contanier specific, but does anyone know
> if Tomcat 4.x allow for jsp:include actions within a BodyTag?

Using JSP1.2 (i.e. Tomcat-4.0), you can have the behavior
you're looking for.

For example, I have a JSP page with the following:
(my filter tag in that case simply copies the tag's body content 
to the page's output (pageContext().getOut()))

  <ftl:filter>
  <pre>
  BodyContent Line (included below)
  <jsp:include page="included.html"/>
  BodyContent Line (included above)
  </pre>
  </ftl:filter>

And the output is:

BodyContent Line (included below)
Included Line 1
Included Line 2
BodyContent Line (included above)


Prior to JSP1.2, the buffer of the JSP page had to be flushed
before the include could take place (that's why flush="true"
was then mandatory). This is no more the case in JSP1.2.

    -- Pierre

"Ward, Jeff" wrote:
> 
>   Yup, it's part of the spec to do that. The include writes directly to the
> request while the tag writes to the body. (which is buffered until the end
> in which case it is written to it's parent or if no parent then the
> request.) The only way I have found to get around this is to write my own
> include and included page tags.
>   My include stuffs the current out into the request and then calls the
> included page. The included page tag grabs the out from the request and
> writes to it instead of the request, the result is an inline include.
>   Another way is to have an include that uses a URL and writes the result
> inline. The upside is you don't need the included page tags but the down
> side is it isn't an include in the JSP since anymore (it has a different
> request) and it takes more resources (it is another hit to your site).
>   This is just an ugliness in the spec because they didn't think about
> nested tags that deeply.
>   Hope this helps.
>   -Jeff Ward
> 
>  -----Original Message-----
> From:   Alex Tang [mailto:altitude@airflash.com]
> Sent:   Tuesday, January 30, 2001 10:16 AM
> To:     jsp-interest@java.sun.com
> Cc:     taglibs-user@jakarta.apache.org
> Subject:        Using a jsp:include action (JSP 1.1) within a BodyTag taglib
> tag
> 
> hi folks.  (Sorry for the wide distribution, this question seems to span
> both the JSP and taglib realm).
> 
> I'm having a problem with the interaction of a taglib BodyTag and a
> jsp:include action (or an equivalent taglib tag that uses a
> pageContext.forward()).  For example, if I have:
> 
>      <foo:myBodyTag>
>        Blah Blah...
>        <jsp:include page="..."/>
>      </foo:myBodyTag>
> 
> The output from the jsp:include action always appears BEFORE the output
> from the myBodyTag taglib tag.
> 
> (BTW, I'm using Tomcat 3.1)
> 
> In reading the JSP 1.1 spec, section 5.4.5 says
> 
>      The BodyContent Class
> 
>      The BodyContent is a subclass of JspWriter that can be used to
>      process body evaluations so they can retrieved later on. The
>      class has methods to convert its contents into a String, to
>      read its contents, and to clear the contents.
> 
>      The buffer size of a BodyContent object is "unbounded". A
>      BodyContent object cannot be in autoFlush mode. 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.
> 
>      ...
> 
> >From the last sentence, does this mean that it is illegal to use a
> jsp:include action (or an equivalent taglib tag that performs a
> pageContext.include()) within a BodyTag?
> 
> Is there a way to get around this in JSP 1.1 (Specifically Tomcat 3.x)?
> Would setting the page buffer to none help?  (If so, what problems or
> drawbacks are there for settign the page buffer to none?)
> 
> I've looked through the JSP 1.2 spec (although not completely), and I
> did not see any mention of this type of restriction.  Is this correct?
> 
> I realize that this is somewhat contanier specific, but does anyone know
> if Tomcat 4.x allow for jsp:include actions within a BodyTag?
> 
> Thank you for your time.
> 
> ...alex...

Mime
View raw message