tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ben Kelley" <ben_kel...@ubsw.com>
Subject Internationalisation problems in Tomcat 3.3?
Date Mon, 16 Jul 2001 07:09:53 GMT
Hi.

I've seen a couple of posts about problems with i18n and Tomcat. I am having
trouble with this, and at this point I'm suspecting a bug somewhere.

The same test servlet works fine with Apache JServ 1.0, but displays
"???????" in Tomcat 3.3m4.

Consider the test servlet below. If you call http://yourserver/servlet/test
you get just "English". if You call http://yourserver/servlet/test?lang=ja
it should display some Japanese (encoded as euc-jp).

The Japanese text uses the unicode escapes for the appropriate characters.

As I was writing this e-mail, I hit refresh on my site and the Japanese
version worked. I loaded up some English pages, and the Japanese version
went back to "??????".

If you uncomment out the resp.getCharacterEncoding() lines you should find
that you get the correct answer for each case.

Any thoughts?

     - Ben Kelley.

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;

public class test extends HttpServlet
{
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    {
        try
        {
            if ((req.getParameter("lang") != null) &&
req.getParameter("lang").equals("ja"))
            {
                resp.setContentType("text/html; charset=euc-jp");
                PrintWriter out = resp.getWriter();
                out.println("<html><head><title>Japanese</title></head>");
                out.println("<body>");
                out.println("<p>Japanese</p>");
                // out.println("<p>Encoding is " +
resp.getCharacterEncoding());

                out.println("<p>Location = \u6240\u5728\u5730\uff1a</p>");
                out.println("<p>Latest research updates =
\u76f4\u8fd1\u306e\u30ea\u30b5\u30fc\u30c1\u53ca\u3073\u66f4\u65b0</p>");
                out.println("</body>");
                out.println("</html>");
            }
            else
            {
                resp.setContentType("text/html; charset=iso-8859-1");
                PrintWriter out = resp.getWriter();
                out.println("<html><head><title>English</title></head>");
                out.println("<body>");
                out.println("<p>English</p>");
                // out.println("<p>Encoding is " +
resp.getCharacterEncoding());
                out.println("</body>");
                out.println("</html>");
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

Ben Kelley - ben_kelley@ubsw.com
Senior Web Developer - ResearchWeb
UBS Warburg, Sydney, Australia


Visit our website at http://www.ubswarburg.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.


Mime
View raw message