A fellow on the JSP-INTEREST list asked a question about displaying
Unicode characters to "System.out", which got me wondering if I could use
them in Servlets as well -- I'm not too strong on internationalization
yet.

As a "HelloWorld" for Unicode, I started with ISO-8859 documents and then
switched to UTF-8, which is cooler.  I have ASCII, Latin-1, Greek, Hebrew,
and Japanese. Most of the characters won't display in a default Windows
install without installing individual language packs, which are very
simple to add.

To install and Unicode/ISO language pack in Windows 2000
Select "Internet Explorer -> View -> Encoding -> More -> [Language]"
It will prompt for the Windows 2000 disk.

Since I did this, I thought others might find it interesting.

                                        Michael Akerman


Here is the compiled servlet:
-------------------------------
http://clio.uark.edu/servlet/espresso.mike.UnicodeServlet


Here is the source:
----------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class UnicodeServlet extends HttpServlet
{
        public void doGet (HttpServletRequest req, HttpServletResponse res) throws 
ServletException, IOException
        {
                res.setContentType("text/html; charset=UTF-8");
                PrintWriter out = res.getWriter();

                out.println("<html>");
                out.println("<head><meta http-equiv=\"Content-Type\" 
content=\"text/html; charset=UTF-8\"></head>");
                out.println("<body>");
                out.println("<table width=80% style='font: bold 14pt Times'>");
                for(int i=0x0030; i<=0x00ff; i++)
                {
                        if ( i % 16 == 0 ) out.println("<tr>");
                        out.print("<td>"); out.write(i);
                }
                for(int i=0x0370; i<=0x03ff; i++)
                {
                        if ( i % 16 == 0 ) out.println("<tr>");
                        out.print("<td>"); out.write(i);
                }
                for(int i=0x3040; i<=0x30ff; i++)
                {
                        if ( i % 16 == 0 ) out.println("<tr>");
                        out.print("<td>"); out.write(i);
                }
                for(int i=0x0590; i<=0x05ff; i++)
                {
                        if ( i % 16 == 0 ) out.println("<tr>");
                        out.print("<td>"); out.write(i);
                }
                out.println("</table>");
                out.println("</body>");
                out.println("</html>");
        }
}

                                        Michael Akerman


-----------------------------------------------------------------

[EMAIL PROTECTED]                    Information Services
(501) 575-5870                          University of Arkansas
http://www.uark.edu/~mike

-----------------------------------------------------------------

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to