pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
[personal profile] pne

http://java.sun.com/j2se/corejava/intl/reference/faqs/index.html#encoding-override:

Why does the response character encoding in my JSP-based application change after I set it?

In some cases web applications set the response character encoding (which corresponds to the charset value of the content type), but the web page sent to the browser is actually encoded in a different encoding. This problem can occur when using a Servlet 2.3 based container together with the JavaServer Pages Standard Tag Library. The sequence of events is:

  1. Application sets the content type including a charset value. This sets the response character encoding.
  2. Application uses a JSTL tag that accesses a resource bundle.
  3. JSTL sets the response locale to the locale that led to the resource bundle found.
  4. The container sets the response character encoding to an encoding that's suitable for the response locale, but may be different from the previously set character encoding.

This problem was solved in the Servlet 2.4 specification by distinguishing between explicit and implicit character encoding specifications. Setting the character encoding through the content type or via the new method ServletResponse.setCharacterEncoding are explicit specifications, while determining it from a locale setting is an implicit specification. Implicit specifications cannot override explicit specifications, so event 4) above does not occur.

If your application needs to be compatible with containers based on older specifications, you must freeze the character encoding by calling ServletResponse.flushBuffer between the explicit character encoding specification and the first use of custom actions that might implicitly determine the character encoding.

Profile

pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
Philip Newton

June 2015

S M T W T F S
 12 3456
78910111213
14151617181920
2122232425 2627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Wednesday, 31 December 2025 22:35
Powered by Dreamwidth Studios