10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Character Sets and Encodings<br />

472<br />

pages, you can use the JSTL fmt:requestEncoding tag. You must call the method or tag before<br />

parsing any request parameters or reading any input from the request. Calling the method or<br />

tag once data has been read will not affect the encoding.<br />

Page Encoding<br />

For JSP pages, the page encoding is the character encoding in which the file is encoded.<br />

For JSP pages in standard syntax, the page encoding is determined from the following sources:<br />

■ <strong>The</strong> page encoding value of a JSP property group (see “Setting Properties for Groups of JSP<br />

Pages” on page 177) whose URL pattern matches the page.<br />

■ <strong>The</strong> pageEncoding attribute of the page directive of the page. It is a translation-time error to<br />

name different encodings in the pageEncoding attribute of the page directive of a JSP page<br />

and in a JSP property group.<br />

■ <strong>The</strong> CHARSET value of the contentType attribute of the page directive.<br />

If none of these is provided, ISO-8859-1 is used as the default page encoding.<br />

For JSP pages in XML syntax (JSP documents), the page encoding is determined as described in<br />

section 4.3.3 and appendix F.1 of the XML specification.<br />

<strong>The</strong> pageEncoding and contentType attributes determine the page character encoding of only<br />

the file that physically contains the page directive. A web container raises a translation-time<br />

error if an unsupported page encoding is specified.<br />

Response Encoding<br />

<strong>The</strong> response encoding is the character encoding of the textual response generated by a web<br />

component. <strong>The</strong> response encoding must be set appropriately so that the characters are<br />

rendered correctly for a given locale. A web container sets an initial response encoding for a JSP<br />

page from the following sources:<br />

■ <strong>The</strong> CHARSET value of the contentType attribute of the page directive<br />

■ <strong>The</strong> encoding specified by the pageEncoding attribute of the page directive<br />

■ <strong>The</strong> page encoding value of a JSP property group whose URL pattern matches the page<br />

If none of these is provided, ISO-8859-1 is used as the default response encoding.<br />

<strong>The</strong> javax.servlet.ServletResponse.setCharacterEncoding,<br />

javax.servlet.ServletResponse.setContentType, and<br />

javax.servlet.ServletResponse.setLocale methods can be called repeatedly to change the<br />

character encoding. Calls made after the servlet response’s getWriter method has been called<br />

or after the response is committed have no effect on the character encoding. Data is sent to the<br />

response stream on buffer flushes (for buffered pages) or on encountering the first content on<br />

unbuffered pages.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!