0

My servlet looks like this

  protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
  {
    PrintWriter out=response.getWriter();

    out.println("<Html><Head><Title>Signup</Title></Head>\n<Body>\n");
    out.println("\u5982 电话\n");
    out.println("</Body>\n</Html>");
  }

My browser can display Chinese characters from other websites. I'm trying 2 different ways to display Chinese characters, but they all showed up as ??? What's the correct way to do it ?

Makoto
  • 104,088
  • 27
  • 192
  • 230
Frank
  • 30,590
  • 58
  • 161
  • 244
  • Have you verified that your browser+system+font combination will display any Chinese at all, by outputing html escaped versions of the unicode? e.g. "如"? http://unicodinator.com – jwl Jun 09 '11 at 15:40
  • 1
    See http://stackoverflow.com/questions/1849058/change-encoding-of-httpservletresponse – Michael Brewer-Davis Jun 09 '11 at 15:50

4 Answers4

1

No explicit encoding has been set for the response. The response would therefore be written by the container with the default encoding of ISO-8859-1.

You'll therefore need to specify the appropriate character encoding using the HttpServletResponse.setCharacterEncoding() or HttpServletResponse.setContentType methods. This would be either of:

response.setCharacterEncoding("GB18030");
response.setContentType("text/html; charset=GB18030");

You may also use UTF-8 as the explicit encoding.

Vineet Reynolds
  • 76,006
  • 17
  • 150
  • 174
0

Just setting the character encoding as UTF-8 worked for me.

response.setCharacterEncoding("UTF-8")
Hasan Sawan
  • 391
  • 2
  • 14
0

Try adding

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
jmj
  • 237,923
  • 42
  • 401
  • 438
0

You would need to send Unicode, have your servlet send UTF-8, and have the browser locale set up properly to interpret the characters correctly.

duffymo
  • 305,152
  • 44
  • 369
  • 561