tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Filters and JSP
Date Fri, 15 Apr 2011 19:31:20 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill,

On 4/14/2011 8:11 PM, Bill Davidson wrote:
>         public MyResponseWrapper( HttpServletResponse response ) throws
> IOException  {
>             super(response);
>             myOutputStream = new MyOutputStream(response);
>             OutputStreamWriter osw = new
> OutputStreamWriter(myOutputStream, response.getCharacterEncoding());
>             printWriter = new PrintWriter(osw);
>         }

My experience has been that handling cases where the servlet can call
either response.getOutputStream or response.getWriter is a pain in the
neck: you've got to be very careful to handle either scenario.

Are any of your methods catching IOException and not logging them?

> The problem seems to be that it only calls write(byte[], int, int)
> once when it's a JSP.

Regardless of the amount of data that the JSP /should/ be returning?

> It will get called multiple times for a servlet but just
> once for
> the JSP.   It's getting called with offset = 0 and len = 8192, and
> that's about
> how much output I get.  My page is always truncated.

If you remove your filter, does the page return the expected content to
the client? If so, it's your filter that is broken :(

> Obviously there is
> some sort of buffered writer calling my write() routine.

JSPs support (and probably always use) buffered output. It's not a
surprise that you are getting a large amount of data in a single write()
call... though if there were more than 8192 bytes of total content, I
would expect that multiple write() calls would be made.

> All of the output methods from ServletOutputStream are overridden and
> logged, so I know what is getting called.

Can you give us an example of a log dump during JSP evaluation?

> Also, flush() gets called at the end for servlets but never gets called
> for a JSP.

A JSP is just a servlet that has been compiled from a JSP source, so
they're really not that different. A difference I can think of is that
many servlets might explicitly call flush() while a JSP-generated one
does not, and Tomcat calls flush() before closing the stream. Since your
filter has lost control /before/ Tomcat flushes and closes the stream
back to the client, you may be missing this flush() call altogether.


> Is there something I need to do in my JSP's?

You could try disabling buffering, just to see if things improve. Your
performance will suffer, of course.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2onQgACgkQ9CaO5/Lv0PCcUwCgmp9KnTDeti7Bd25gyy8LHjL4
ICwAn1FVokAtb1YRqwPpxoTRbKqKvk7a
=6JRm
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message