background image

Page Encoding

<< Character Encoding | Calls to setContentType >>
<< Character Encoding | Calls to setContentType >>

Page Encoding

you can use the JSTL fmt:requestEncoding tag. You must call the method or tag before
parsing any request parameters or reading any input from the request. Calling the method or
tag once data has been read will not affect the encoding.
Page Encoding
For JSP pages, the page encoding is the character encoding in which the file is encoded.
For JSP pages in standard syntax, the page encoding is determined from the following sources:
The page encoding value of a JSP property group (see
"Setting Properties for Groups of JSP
Pages" on page 179
) whose URL pattern matches the page.
The pageEncoding attribute of the page directive of the page. It is a translation-time error to
name different encodings in the pageEncoding attribute of the page directive of a JSP page
and in a JSP property group.
The CHARSET value of the contentType attribute of the page directive.
If none of these is provided, ISO-8859-1 is used as the default page encoding.
For JSP pages in XML syntax (JSP documents), the page encoding is determined as described in
section 4.3.3 and appendix F.1 of the XML specification.
The pageEncoding and contentType attributes determine the page character encoding of only
the file that physically contains the page directive. A web container raises a translation-time
error if an unsupported page encoding is specified.
Response Encoding
The response encoding is the character encoding of the textual response generated by a web
component. The response encoding must be set appropriately so that the characters are
rendered correctly for a given locale. A web container sets an initial response encoding for a JSP
page from the following sources:
The CHARSET value of the contentType attribute of the page directive
The encoding specified by the pageEncoding attribute of the page directive
The page encoding value of a JSP property group whose URL pattern matches the page
If none of these is provided, ISO-8859-1 is used as the default response encoding.
The
setCharacterEncoding
,
setContentType
, and
setLocale
methods can be called repeatedly to
change the character encoding. Calls made after the servlet response's getWriter method has
been called or after the response is committed have no effect on the character encoding. Data is
sent to the response stream on buffer flushes (for buffered pages) or on encountering the first
content on unbuffered pages.
Character Sets and Encodings
The Java EE 5 Tutorial · September 2007
474