×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

Java Unicode问题请教

无法正常显示中文字符。环境:JSD 1。4 + tomcat 4.1.30 + mysql 4.1.2a.

我试了这些:
1. declare the jsp page meta data as utf-8:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

2. declaring the jsp page property utf-8:
<%@ page language="java" pageEncoding="UTF-8" %>

3. using Servlet filter to enforce UTF-8 request and response encoding

4. declare JDBC drive connection as UTF-8:
jdbc:mysql://localhost:3306/roller?user=roller&amp;password=roller&amp;autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8

5. setup mysql encoding in my.ini:

[mysqld]
default-character-set=utf8

这些应该解决问题, 但还是不成功, 请问问题在哪里

Thanks for your comments
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / Java Unicode问题请教
    无法正常显示中文字符。环境:JSD 1。4 + tomcat 4.1.30 + mysql 4.1.2a.

    我试了这些:
    1. declare the jsp page meta data as utf-8:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    2. declaring the jsp page property utf-8:
    <%@ page language="java" pageEncoding="UTF-8" %>

    3. using Servlet filter to enforce UTF-8 request and response encoding

    4. declare JDBC drive connection as UTF-8:
    jdbc:mysql://localhost:3306/roller?user=roller&amp;password=roller&amp;autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8

    5. setup mysql encoding in my.ini:

    [mysqld]
    default-character-set=utf8

    这些应该解决问题, 但还是不成功, 请问问题在哪里

    Thanks for your comments
    • 手头没有以前的代码,按照我的回忆
      1. 转request

      strVal = ((String [])request.getParameterValues(strKey))[0];
      strVal = new String(strVal.getBytes(ENCODING_ISO), ENCODING_GB);

      2. 设response

      res.setContentType("text/html; charset=" + ENCODING_GB);

      3. jsp开头声明

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

      4. 和mysql的连接不用设置

      5. give it a try and good luck
      • 谢谢流水, 发现是MYSQL 问题, 重新建立TABLE : CREATE TABLE t1 {。。} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci, MYSQL 4。1 以前不完全支持UNICODE!!, 终於一下解决问题。 还解决了Collation SORTING。