You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "Nedwick, Robert" <Ro...@B2eMarkets.com> on 2003/04/04 16:18:27 UTC

Question on JSTL fmt tags and response encoding

I'm currently working on enabling an application for Asian language support.
The application is already supports multiple W.European languages.  It uses
the JSTL fmt tags for most, but not all, screens.  To support the Asian
languages, we've decided to use the UTF-8 charset for all pages so we can
always use the same charset when decoding request parameters regardless of
what language the user is submitting the data in.
 
I put together a prototype with a JSP page that set the contentType to
"text/html; charset=utf-8" and then displayed the contents of a Japanese
locale resource bundle.  When running this test, I noticed that the charset
was overridden to be Shift_JIS.  This causes problems since now any forms
submitted from that page will be sent via Shift_JIS encoding, and since I'm
expecting UTF-8, the screen fails.  I know from reading the specification
that using the various fmt tags will result in the response.setLocale()
method being called, which will then additionally set the charset.  

The question I have is: why do the fmt tags automatically call setLocale for
you?  I can understand the <fmt:setLocale /> tag doing it, but I'm trying to
understand why <fmt:setBundle /> and <fmt:message /> set the response Locale
as well, since that overrides any other charset that may have been
explicitly requested by the JSP developer when using a page directive to set
the charset explicitly.

To work around this, I have implemented a ServletFIlter that passes a custom
response wrapper along the filter chain.  The custom response object
prevents the charset from being set to anything other than UTF-8.  This
seems like a reasonable solution, especially since our application needs to
support multiple application servers.

Are there there any other better ways to guarantee that the UTF-8 charset
will be used for my JSP pages regardless of the JSTL tags attempting to set
the Locale/charset automatically?

Thanks for any info,
Robb
robert.nedwick@b2emarkets.com

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


Re: Question on JSTL fmt tags and response encoding

Posted by Vernon <ve...@gatewaytech.com>.
Robert,

See below.

On Fri, 4 Apr 2003 09:18:27 -0500, Nedwick, Robert 
<Ro...@B2eMarkets.com> wrote:

> I'm currently working on enabling an application for Asian language 
> support.
> The application is already supports multiple W.European languages.  It 
> uses
> the JSTL fmt tags for most, but not all, screens.  To support the Asian
> languages, we've decided to use the UTF-8 charset for all pages so we can
> always use the same charset when decoding request parameters regardless 
> of
> what language the user is submitting the data in.
> I put together a prototype with a JSP page that set the contentType to
> "text/html; charset=utf-8" and then displayed the contents of a Japanese
> locale resource bundle.  When running this test, I noticed that the 
> charset
> was overridden to be Shift_JIS.  This causes problems since now any forms
> submitted from that page will be sent via Shift_JIS encoding, and since 
> I'm
> expecting UTF-8, the screen fails.  I know from reading the specification
> that using the various fmt tags will result in the response.setLocale()
> method being called, which will then additionally set the charset.
>

To my observation, an application scope locale can be set without any 
impress on the response locale. That is the response locale can be en_US 
and the application locale can be es at the same time.

> The question I have is: why do the fmt tags automatically call setLocale 
> for
> you?  I can understand the <fmt:setLocale /> tag doing it, but I'm trying 
> to
> understand why <fmt:setBundle /> and <fmt:message /> set the response 
> Locale
> as well, since that overrides any other charset that may have been
> explicitly requested by the JSP developer when using a page directive to 
> set
> the charset explicitly.

I don't have any answers for your questions. But, have you tried the set 
method of the javax.servlet.jsp.jstl.core.Config class?

>
> To work around this, I have implemented a ServletFIlter that passes a 
> custom
> response wrapper along the filter chain.  The custom response object
> prevents the charset from being set to anything other than UTF-8.  This
> seems like a reasonable solution, especially since our application needs 
> to
> support multiple application servers.
>
> Are there there any other better ways to guarantee that the UTF-8 charset
> will be used for my JSP pages regardless of the JSTL tags attempting to 
> set
> the Locale/charset automatically?


>
> Thanks for any info,
> Robb
> robert.nedwick@b2emarkets.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>

Hope this helps.

-- 
Vernon

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