Page character encoding is the encoding in which the JSP source file is written.
The JSP 2.0 specification distinguishes between two syntaxes when detecting
the page character encoding:
For files in standard JSP syntax, encoding is detected
by looking at two primary sources of information: First in the deployment descriptor
(the web.xml file) for a page-encoding element in a jsp-property-group whose URL
pattern matches the file; then for a pageEncoding attribute in the page itself.
If neither is present, the charset of a JSP file's contentType attribute is used,
or the ISO 8859-1 character encoding is used as the ultimate fallback.
For files in JSP document syntax, the encoding is detected as
described in the XML specification; this means that UTF-8 is the
default and any other encoding must be declared in the XML declaration at
the beginning of the file.
To set the page character encoding for a file in standard JSP syntax:
For JSP files (standard syntax), the page encoding is set as follows:
Create a JSP file that uses
standard JSP syntax. Right-click the JSP file and
choose Properties. Note that the Encoding property is set to the encoding for the project. This is the
JSP file's page encoding. You cannot
change the page encoding in the Properties sheet.
The place where you set the page encoding depends on whether you want to
set it for an individual JSP file or for a group of JSP files together. The
following step guides you through the setting of the page encoding for JSP files.
Do one of the following to change the JSP file's page encoding:
Set the page character encoding for an individual JSP file.
Double-click the JSP file so that it opens in the Source Editor. The
default pageEncoding attribute of a JSP file created in the IDE is as follows:
<%@page pageEncoding="UTF-8"%>
You can change the page encoding in the JSP file and save it. Note that
the IDE warns you if you try to save a character set that is not valid for JSP pages.
Alternatively, set the page encoding in the contentType attribute
of the page directive instead. The
default contentType attribute of a JSP file does not contain a charset value,
because the pageEncoding attribute handles page encoding by default.
However, you can add a charset value as follows:
<%@page contentType="text/html;charset=UTF-8"%>
Set the page character encoding for groups of JSP files.
Expand the Web Pages node, then the WEB-INF node, and then double-click the web.xml file.
Click Pages at the top of the editor and then click the JSP Property Groups header to open
the JSP Property Groups section.
Use the JSP Property Groups section to add, remove, and
view a web application's JSP property groups. A JSP property group is a set of properties
defined for a group of JSP files within a web application. One of the properties you can
set here is the page encoding value for a group of JSP files.
Only if the other two are absent is the contentType attribute of a JSP file's
page directive used as the page encoding.
If none of these are provided, utf-8 is used as the page encoding.
A translation-time error results if you define the page encoding with one value in the JSP
property group and then give it a different value in an invidual JSP file's pageEncoding directive.
To set the page character encoding for a file in JSP document syntax:
For JSP documents (XML syntax), the page encoding is set as follows:
Create a JSP file that uses XML syntax.
Right-click the JSP document and
choose Properties. Note that the Encoding property is set to the encoding for the project. This is the
JSP document's page encoding. You cannot
change the page encoding in the Properties sheet.
For JSP documents, you can change the page character encoding in one place only:
The encoding attribute of an XML declaration at the beginning
of the file. The XML declaration is also known as the XML prolog.
The page encoding for JSP documents may also be described
in an individual JSP document's page directive or in a JSP property
group, as long as the values described there match the value derived from
the XML prolog. It is a translation-time error to specify different encodings
in the XML prolog and in the declarations in a JSP document or JSP property
group. If the XML prolog does not specify an encoding, the UTF-8 encoding
is derived instead.
Double-click the JSP file so that it opens in the Source Editor. The
default XML declaration of a JSP document created in the IDE includes an
encoding attribute as follows:
<?xml version="1.0" encoding="UTF-8"?>
You can change the encoding in the XML declaration and save the JSP document.