tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Barker" <wbar...@wilshire.com>
Subject Re: Setting locale encoding in Filter
Date Thu, 10 Apr 2003 07:23:45 GMT
You're setLocale et. al. calls should come before 'next.doFilter'.
Otherwise (esp. with JSP pages) the response may be committed before control
is returned to your Filter.  In this case, you are now longer allowed to
change the settings (and Tomcat should throw an IllegalStateExecption).

"hacking bear" <hackingbear@hotmail.com> wrote in message
news:F49dyvqSgnpvI4NNIiY00006bde@hotmail.com...
> Hello,
>
> My app needs to handle multiple locale/encoding and since the user chooses
> locale at login I try to just set the locale encoding in a servlet filter
so
> that I don't have to do that in every page or servlet:
>
> void doFilter(request, response, FilterChain next) {
>      if (next != null) {
>          next.doFilter(request, response);
>      }
>      response.setLocale(locale);
>      response.setContentType("text/html; charset=" + encoding);
>      response.addHeader("Cache-Control", "no-cache");
>      request.setCharacterEncoding(encoding);
> }
>
> 1. This almost works except some JSP pages sometimes (but not always)
> displaying '?' garbage character. But if I set the response's
> locale/encoding again at the beginning of the JSP page, the problem goes
> away.
>
> 2. If I move the set locale/encoding codes before the next.doFilter(),
then
> all pages display garbage only.
>
> Is this the right way? What do I do wrong?
>
> Thanks.
> -HB
>
>
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail




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


Mime
View raw message