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/21 02:28:52 UTC

jsp:include -- writer vs. output stream AND what should be included?

I have two issues to raise re: includes

1.  If I include a static HTML page and then include a servlet, I will get an
exception if the servlet attempts to call request.getOutputStream() saying that
a writer is already in use.  When you are call existing servlets that use the
output stream, you must now rewrite those servlets in order to use them.  

Is there some workaround?  I wrote my own include tag for this purpose, but it
would seem better to me if the output stream and writer for the request could
be merged in some way that you could safely use both of them.  Does anybody
know anything more on this issue?


2.  If I include another html page using jsp:include, it's not very smart.  It
just includes the entire page.  This leads to pages with multiple <html> and
<body> elements.  How can you get all these merged into one logical document
using jsp tags?  Is this even possible?  What about JavaScript naming
collisions?  Are there any tricks to resolve these?

Thanks for any information,

Mike Taylor
mtaylor@emeraldcave.net


Re: jsp:include -- writer vs. output stream AND what should be included?

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Michael Taylor wrote:

> I have two issues to raise re: includes
>
> 1.  If I include a static HTML page and then include a servlet, I will get an
> exception if the servlet attempts to call request.getOutputStream() saying that
> a writer is already in use.  When you are call existing servlets that use the
> output stream, you must now rewrite those servlets in order to use them.
>

That is the way that the spec requires things to work.

>
> Is there some workaround?  I wrote my own include tag for this purpose, but it
> would seem better to me if the output stream and writer for the request could
> be merged in some way that you could safely use both of them.  Does anybody
> know anything more on this issue?
>

The output stream should be used when you are writing binary data.

The writer should be used when you are writing text data.

You should not need to be doing both of these things on the same
response.

>
> 2.  If I include another html page using jsp:include, it's not very smart.  It
> just includes the entire page.  This leads to pages with multiple <html> and
> <body> elements.  How can you get all these merged into one logical document
> using jsp tags?  Is this even possible?  What about JavaScript naming
> collisions?  Are there any tricks to resolve these?
>

Make the targets of your includes be "incomplete" pages (without the
extra <html>
and <body> elements).

One very important thing to remember is that the servlet container is
paying *zero*
attention to the actual content of your pages.  That is up to you.  It's
only job
is to copy the contents of the included resource into the output of the
current
one.

>
> Thanks for any information,
>
> Mike Taylor
> mtaylor@emeraldcave.net
>

Craig McClanahan