JSP Tutorials - Herong's Tutorial Examples - v5.11, by Herong Yang
Static HTML Text in JSP Page in XML Syntax
This section provides a tutorial example to test how non-ASCII characters entered as static text in JSP pages in XML syntax are handled by the JSP server and returned to Web browsers.
In the third test, the static text is inserted into a JSP page in XML syntax:
<?xml version="1.0" encoding="gb2312"?> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.3"> <!--jsp:directive.page contentType="text/html; charset=gb2312"/--> <jsp:directive.page contentType="text/html; charset=gb2312"/> <!-- StaticGB2312XML.jspx - Copyright (c) 2006 HerongYang.com. All Rights Reserved. --> <html> <body> <p> GB2312-binary: 쮵쏷=(0xCBB5C3F7)<br/> GB2312-#xHEX: 쮵쏷<br/> GB2312-\uHEX: \uCBB5\uC3F7<br/> Unicode-binary: ----=(0x8bf4660e)<br/> Unicode-#xHEX: 说明<br/> Unicode-\uHEX: \u8bf4\u660e<br/> Unicode-UTF8: 说明=(0xE8AFB4E6988E)<br/> </p> </body> </html> </jsp:root>
If you view this page with IE, you should see that only GB2312-binary and Unicode-#xHEX lines are displayed correctly.
Here are the related lines of the generated Java class file:
... response.setContentType("text/html; charset=gb2312"); ... out.write("GB2312-binary: 说明=(0xCBB5C3F7)"); out.write("<br/>"); out.write("\n"); out.write("GB2312-#xHEX: ??"); out.write("<br/>"); out.write("\n"); out.write("GB2312-\\uHEX: \\uCBB5\\uC3F7"); out.write("<br/>"); out.write("\n"); out.write("Unicode-binary: ----=(0x8bf4660e)"); out.write("<br/>"); out.write("\n"); out.write("Unicode-#xHEX: 说明"); out.write("<br/>"); out.write("\n"); out.write("Unicode-\\uHEX: \\u8bf4\\u660e"); out.write("<br/>"); out.write("\n"); out.write("Unicode-UTF8: ???=(0xE8AFB4E6988E)"); out.write("<br/>"); ....
I have tried to change charset to UTF-8, but it did not work. JSP pages in XML syntax are always decoded as ISO-8859-1. May be there is a setting somewhere to control this, but I don't know.
Table of Contents
JSP (JavaServer Pages) Overview
Tomcat Installation on Windows Systems
Syntax of JSP Pages and JSP Documents
JavaBean Objects and "useBean" Action Elements
Managing HTTP Response Header Lines
►Non-ASCII Characters Support in JSP Pages
Characters Traveling from JSP Files to Browser Screens
Handling ASCII Characters in JSP Pages
Presenting Non ASCII Characters in HTML Documents
Entering Non ASCII Characters in JSP Pages
Java Strings as non-Unicode Encoded Byte Sequences
Java Strings as Unicode Encoded Byte Sequences
Entering Non-ASCII Characters as Static Text
Static HTML Text in JSP Page in Standard Syntax
►Static HTML Text in JSP Page in XML Syntax
Supporting Characters in Multiple Languages
Overview of JSTL (JSP Standard Tag Libraries)
Multiple Tags Working Together
Using Tomcat on CentOS Systems
Connecting to SQL Server from Servlet