You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Michael Taylor <mt...@emeraldcave.net> on 2000/07/25 14:30:23 UTC

JSP with taglibs -- output in wrong order without flush?

I have a project where I am using taglibs to hide complexity in a JSP page.  If
I include another page into the JSP within this tag, I find that the output
comes out in the wrong order.

The included content is put into the output BEFORE the preceding JSP code.  For
example:

<html><head><title>Example</title></head>
<body>
<foo:mytag />
</body>
</html>

When I did this, I got the included text, followed by all the other text.  Now,
if within my tag, I call upon the writer and flush() the output then the output
appears in the correct order.

When I did a BodyTag, with included content for both the start and end tag I
had far worse results.

In all cases, adding flush() calls solved the problem.


Is this a bug, or something I am not understanding?

Thanks in advance,

Mike

  -- 
Michael Taylor, mtaylor@emeraldcave.net

Re: JSP with taglibs -- output in wrong order without flush?

Posted by Serge Knystautas <se...@lokitech.com>.
Michael,

I'm guessing the problem is with how you're accessing the writer.  If
you do something like pageContext.getRequest().getWriter() (you might
have to cast, don't remember exactly), you're in fact creating a new
JspWriter instance.  What you should do is use the bodyOut/bodyContent
(whatever you're calling it locally) and call getEnclosingWriter(). 
This will give you the JspWriter that the JSP was using directly. 
Otherwise you write to the new writer instance, which then will cause
order problems as you describe.  Check over some of the examples to see
how this is done.

Serge Knystautas
Loki Technologies
http://www.lokitech.com/

Michael Taylor wrote:
> 
> I have a project where I am using taglibs to hide complexity in a JSP page.  If
> I include another page into the JSP within this tag, I find that the output
> comes out in the wrong order.
> 
> The included content is put into the output BEFORE the preceding JSP code.  For
> example:
> 
> <html><head><title>Example</title></head>
> <body>
> <foo:mytag />
> </body>
> </html>
> 
> When I did this, I got the included text, followed by all the other text.  Now,
> if within my tag, I call upon the writer and flush() the output then the output
> appears in the correct order.
> 
> When I did a BodyTag, with included content for both the start and end tag I
> had far worse results.
> 
> In all cases, adding flush() calls solved the problem.
> 
> Is this a bug, or something I am not understanding?
> 
> Thanks in advance,
> 
> Mike
> 
>   --
> Michael Taylor, mtaylor@emeraldcave.net
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org