The "pageEncoding" attribute of JSP page directive
In this section, we will discuss about how to set "pageEncoding" attribute & it's uses with example.
In this section, we will discuss about how to set "pageEncoding" attribute & it's uses with example.
The "pageEncoding" attribute of JSP page directive
In this section, we will discuss about how to set "pageEncoding" attribute &
it's uses with example.
The JSP 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 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.
Example: In this example, we will create
two JSP pages with the same content except their "pageEncoding" attribute.
First JSP page sets attribute "GBK" while second JSP page sets default value
i.e." ISO-8859-1 ".
pageencoding1.jsp
<%@page pageEncoding="GBK" %>
<html>
<head><title>Example of pageEncoding attribute of page directive in
JSP.</title></head>
<body>
<table border="1" cellspacing="0" cellpadding="0" bgcolor="ffff00">
<tr>
<td><strong>æ±This is the example of pageEncoding attribute of page
directive.</strong></td>
</tr>
</table>
</body>
</html>
|
OUTPUT
pageencoding2.jsp
<%@page pageEncoding="ISO-8859-1" %>
<html><html>
<head><title>Example of pageEncoding attribute of page directive in
JSP.</title></head>
<body>
<table border="1" cellspacing="0" cellpadding="0" bgcolor="ffff00">
<tr>
<td><strong>æ±This is the example of pageEncoding
attribute of page directive.</strong></td>
</tr>
</table>
</body>
</html>
|
OUTPUT
NOTE: In this example, see the "æ±" string . The "GBK"
pageEncoding display a different thing as compared to "ISO-8859-1" encoding. The
"ISO-8859-1" encoding is clearly visible.
Download Source code