struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jose L Martinez-Avial (JIRA)" <>
Subject [jira] [Commented] (WW-3651) Struts 2 is calling response.setLocale even though it will not handle the request
Date Wed, 18 Sep 2013 17:26:51 GMT


Jose L Martinez-Avial commented on WW-3651:

I believe this issues is related to, and that
the fix for WW-4199 will also solve this.
> Struts 2 is calling response.setLocale even though it will not handle the request
> ---------------------------------------------------------------------------------
>                 Key: WW-3651
>                 URL:
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Dispatch Filter
>    Affects Versions: 2.2.3
>         Environment: Windows 7, Java 1.6
>            Reporter: Alfredo Osorio
>             Fix For: 2.3.17
> The --> org.apache.struts2.dispatcher.Dispatcher.prepare(HttpServletRequest
request, HttpServletResponse response) is calling response.setLocale(locale) when you specify
a default locale (using struts.locale). This is wrong because consider the
following example:
> This is a static resource stored in the following path:
where myApp is the webcontext and /scripts/utils.js is a java script file.
> 1. A request to /myApp/scripts/utils.js.
> 1. Even though Struts 2 is not going to handle the request
calls prepare.setEncodingAndLocale(request, response);
> which sets the Request Encoding and the Response Locale.
> 2. Servlet Container Response setLocale obtains the character encoding corresponding
to that locale and assign a character encoding to the response. This behavior is correct according
to the spec:
> 3. Struts Execute filter doesn't handle the request so chain.doFilter(request, response);
is called.
> 4. Once all filters are called the servlet container DefaultServlet is called to handle
the request and send the content of the file assigning the response header Content-Type in
which this case it will use the encoding type that was set before by the StrutsPrepareFilter.
This might not correspond to the actual encoding of the file.
> An example of the Header Response Content-Type:
> Content-Type	application/x-javascript;charset=ISO-8859-1
> This only happens when you specify the default locale in the because
of these lines in Dispatcher.prepare():
> {code:java}
> String encoding = null;
> if (defaultEncoding != null) {
>     encoding = defaultEncoding;
> }
> Locale locale = null;
> if (defaultLocale != null) {
>     locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
> }
> {code}
> I think that locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
should be removed because setting locale will set the character encoding. And this has side
effects when requests are made to static resources.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message