×

Loading...

Topic

This topic has been archived. It cannot be replied.
  • 工作学习 / IT技术讨论 / Jabber,could you give me a hint about chinese character processing in JSP?Any one interested in this subject pls come in......
    I'm using windows2000 server(Chinese version) and JDK1.3(standard edition).My JSP engine is JRun3.0.
    In stand alone java applications,I can use system.out to print chinese character to console without trouble;
    In servlet, after adding "response.setContentType("text/html charset=GBK")",the output is OK.
    But in JSP,I've done everything and the output is still ???? or unrecognizable charecters.Below is the scriptlet:
    <%
    String cs="";
    String sss= "目录";
    byte ba[]=sss.getBytes();
    try{
    cs= new String(ba,"GBK" );
    }catch (Exception ee){
    System.out.println("exception");}
    out.println(cs);
    PrintWriter pw = new PrintWriter(out);
    pw.println(cs);
    %>
    • a hint ....
      本文发表在 rolia.net 枫下论坛this is a WINDOW NT enviroment. but I think it the same to Window 2000.You can have a try.
      first modify the "Zone set" (区域设置)in “Control Panel". Set Zone as ”English(Unite states),not set as "Chinese (PRC)". Reboot the system.
      Change your jsp programm as

      <%@ page contentType="text/html;charset=ISO8859_1"%>

      <html>
      <head>
      <title>Untitled</title>
      </head>

      <META http-equiv=Content-Type content="text/html; charset=ISO8859_1">

      <body>
      <%
      //String cs=""; no necessary!
      String sss= "目录";
      //byte ba[]=sss.getBytes(); no necessary!
      try{
      //cs= new String(ba,"GBK" ); no necessary!
      }catch (Exception ee){
      System.out.println("exception");}
      //out.println(cs); no necessary!
      //PrintWriter pw = new PrintWriter(out); no necessary!
      //pw.println(sss);
      out.println(sss);

      %>

      It's no necessary to use GBK and getBytes()!
      good luck!更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • Locales....
      Guys, I have no experiences in handling Chinese characters. But I have ever done some things related to Locales related to French and Germany words.

      You said " you have done everything..". Did you set ContentType?

      I am wondering why you have not used Locales and ResourceBundles.
    • thank you both,pals.I found set content type charset to GB2312 is the best solution.But still my get Property reports "GBK".It's odd but it works.Thank you again.