Static HTML Text in JSP Page in Standard Syntax

This section provides a tutorial example to test how non-ASCII characters entered as static text in JSP pages in standard syntax are handled by the JSP server and returned to Web browsers.

In the second test, the static text is inserted into a JSP page in standard syntax:

<%@ page contentType="text/html; charset=gb2312" %>
<!-- StaticGB2312.jsp
 - Copyright (c) 2012, HerongYang.com, All Rights Reserved.
-->
</html>
</body>
<p>
GB2312-binary: 쮵쏷=(0xCBB5C3F7)<br/>      
GB2312-#xHEX: &#xCBB5;&#xC3F7;<br/>
GB2312-\uHEX: \uCBB5\uC3F7<br/>
Unicode-binary: 说明=(0x8bf4660e)<br/>
Unicode-#xHEX: &#x8bf4;&#x660e;<br/>
Unicode-\uHEX: \u8bf4\u660e<br/>
Unicode-UTF8: 说明=(0xE8AFB4E6988E)<br/>
</p>
</body>
</html>

If you view this page in IE, you will that see both GB2312-binary line and Unicode-#xHEX line are displayed correctly. Here is the explanation:

To appove the above explanation, here is the related lines of the generated Java class file:

   ...      
   response.setContentType("text/html; charset=gb2312");
   ...
   out.write("GB2312-binary: 쮵쏷=(0xCBB5C3F7)<br/>\r\n");
   out.write("GB2312-#xHEX: &#xCBB5;&#xC3F7;<br/>\r\n");
   out.write("GB2312-\\uHEX: \\uCBB5\\uC3F7<br/>\r\n");
   out.write("Unicode-binary: 说明=(0x8bf4660e)<br/>\r\n");
   out.write("Unicode-#xHEX: &#x8bf4;&#x660e;<br/>\r\n");
   out.write("Unicode-\\uHEX: \\u8bf4\\u660e<br/>\r\n");
   out.write("Unicode-UTF8: 璇存�=(0xE8AFB4E6988E)<br/>\r\n");
   ...

If you change the "charset" to utf-8, I am sure Unicode-UTF8 line will be displayed correctly. You know why.

By the way, "charset" can also be specified as "pageEncoding" in the "page" directive statement.

Last update: 2012.

Table of Contents

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat 7 Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

 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 HTML Page

Static HTML Text in JSP Page in Standard Syntax

 Static HTML Text in JSP Page in XML Syntax

 Supporting Characters in Multiple Languages

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Outdated Tutorials

 References

 PDF Printing Version