Home Tutorial Java Jsp The "pageEncoding" attribute of JSP page directive

 
 

Share on Google+Share on Google+
The "pageEncoding" attribute of JSP page directive
Posted on: June 15, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for The "pageEncoding" attribute of JSP page directive :


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 15, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com