《Struts完全中文显示解决方案》
4、表单提交参数中的中文解决问题:例如提交下面的表单,http://localhost:8080/Logon/UserEditAction.do? expression=普通用户。在Action中读取参数expression时,用下面的句子:String expression=request.getParameter("expression");得到的expression是Unicode码,不是我们想要的,先变换成ISO8859-1,变换函数如下:public String toChinese(String ss) {    //处理中文问题,实现编码转换    if (ss != null) {      try {        String temp_p = ss;        byte[] temp_t = temp_p.getBytes("ISO8859-1");        ss = new String(temp_t);      }      catch (Exception e) {        System.err.println("toChinese exception:" + e.getMessage());        System.err.println("The String is:" + ss);      }    }    return ss;}使用expression字符串时通过toChinese处理即可:if(expression==null)expression="";        expression=toChinese(expression);  //处理中文问题,实现编码转换。  这些代码在JavaWebStudio中都是自动完成的,用户只要直接使用就行了。

解决方案 »

  1.   

    《Struts完全中文显示解决方案》
    4、表单提交参数中的中文解决问题:例如提交下面的表单,http://localhost:8080/Logon/UserEditAction.do? expression=普通用户。在Action中读取参数expression时,用下面的句子:String expression=request.getParameter("expression");得到的expression是Unicode码,不是我们想要的,先变换成ISO8859-1,变换函数如下:public String toChinese(String ss) {    //处理中文问题,实现编码转换    if (ss != null) {      try {        String temp_p = ss;        byte[] temp_t = temp_p.getBytes("ISO8859-1");        ss = new String(temp_t);      }      catch (Exception e) {        System.err.println("toChinese exception:" + e.getMessage());        System.err.println("The String is:" + ss);      }    }    return ss;}使用expression字符串时通过toChinese处理即可:if(expression==null)expression="";        expression=toChinese(expression);  //处理中文问题,实现编码转换。  这些代码在JavaWebStudio中都是自动完成的,用户只要直接使用就行了。
      

  2.   

    http://host/a.jsp?name=%3F%A8%B4%3F%3F
    也许我没有说清楚,URL实际上是这样一个形势的,%3F%A8%B4%3F%3F是翻译过的中外。
    对于上面这个URL,调用request.getParameter将无法得到一个正确的中文,而按照上面的方法也是无法得到正确的中文的。
      

  3.   

    你看看Google的做法,都是先转成Unicode,然后request.getParameter接收Unicode,在把Unicode转成中文...你说的%3F%A8%B4%3F%3F是翻译过的中文 就是转成Unicode了吧?
    http://www.google.com/search?hl=zh-CN&newwindow=1&q=%E8%B1%86%E8%85%90%E5%B9%B2&btnG=%E6%90%9C%E7%B4%A2&lr=
      

  4.   

    byte[] temp_t = temp_p.getBytes("ISO8859-1");
      

  5.   

    解决了原来是tomcat的问题,要把URIEncoding设置为正确的encode方式才行。