JSP and JSTL Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 3.09, 2006

Localization / Internationalization - Non ASCII Characters in JSP Pages

Part:   1  2  3  4  5 

JSP/JSTL Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Using Cookies

Using JavaBean Classes

HTTP Response Header Lines

Non ASCII Characters

JSTL and Expression Language

File Upload

Execution Context

JSP Elements

JSP Standard Tag Libraries (JSTL)

JSP Custom Tag

... Table of Contents

This chapter explains:

  • How characters travel from JSP files to browser screens.
  • How ASCII characters work in JSP pages.
  • How to present non ASCII characters in HTML documents.
  • How to enter non ASCII charactetrs in Java strings and contole the output encodings.
  • How Java string works with byte sequences encoded for a local language.
  • How Java string works with Unicode codes - local language independent.
  • How to enter non ASCII characters as static HTML text.
  • How static HTML text works in HTML pages
  • How static HTML text works in JSP pages with standard syntax.
  • How static HTML text works in JSP pages with XML syntax.
  • How to supporting characters from multiple languages.

For more notes on non ASCII codes and Java program localization, see my other books: "Herong's Notes on Unicode" and "Herong's Notes on JDK".

Characters Traveling from JSP Files to Browser Screens

Handling non ASCII characters in JSP files correctly is not an easy task. I have seen many messages on the Wep in this area reporting various frustrating situations. One main reason is that text entered in a JSP file must travel through many steps before being displayed by a browser on a screen.

The following diagram illustrates steps that characters must travel from a JSP file to a browser screen, and computing technologies that are used at different steps:

0. Key Sequences from Keyboard 
      |
      |- Text Editor
      v
1. JSP File
      |
      |- XML Parser
      v
2. Java Source File
      |
      |- Java Compiler
      v
3. Java Class File
      |
      |- Java Virtual Machine
      v
4. HTML Document
      |
      |- Web Server
      v
5. HTTP Response
      |
      |- Internet TCP/IP Connection
      v
6. HTTP Response
      |
      |- Web Browser
      v
7. Characters on the Screen

Since all computing technologies are using ASCII encoding by default, text of ASCII characters can safely travel through those steps without any issues.

However, for non ASCII characters, we have to watch out each steps carefully to make sure that characters are not damaged, and/or decoded correctly if encoded.

ASCII Characters in JSP Pages

As I mentioned earlier, ASCII characters can travel from JSP files to browsers easily without any trouble. Here is a simple JSP file with ASCII characters only:

<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 
   xmlns:c="http://java.sun.com/jstl/core" version="1.2"> 
<!-- HelpASCII.jsp
     Copyright (c) 2002 by Dr. Herong Yang
-->
<jsp:directive.page contentType="text/html"/>
<html><body>
<b>Help</b><br/>
<p>This is a very simple help page...</p>
</body></html>
</jsp:root>

If you view this page with a browser, you will get two lines of characters:

Help
This is a very simple help page...

They are exactly what I entered into the JSP file.

Presenting Non ASCII Characters in HTML Documents

In order to ensure non ASCII characters entered in JSP files to show up on browser screens correctly, we need to understand how non ASCII characters are processed from one step to the other. The processing steps can be grouped into two parts:

  • Outputing HTML documents with non ASCII characters - steps 0, 1, 2, and 3.
  • Presenting non ASCII characters in HTML documents - steps 4, 5, 6, and 7.

(Continued on next part...)

Part:   1  2  3  4  5 

Dr. Herong Yang, updated in 2006
JSP and JSTL Tutorials - Herong's Tutorial Notes - Localization / Internationalization - Non ASCII Characters in JSP Pages