我的环境是
tomcat5.0+mysql5.0+繁体版本(由于台湾客户要繁体)
我的xml
<?xml version="1.0" encoding="big5"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
  <jsp-config>
    <jsp-property-group>
      <description>Special property group for JSP Configuration JSP example.</description>
      <display-name>JSPConfiguration</display-name>
      <url-pattern>*.jsp</url-pattern>
      <url-pattern>*.html</url-pattern>
      <el-ignored>true</el-ignored>
      <page-encoding>GBK</page-encoding>
      <scripting-invalid>false</scripting-invalid>
    </jsp-property-group>
  </jsp-config>
</web-app>
我的数据链接这样的:
conn=jdbc:mysql://127.0.0.1/tis?user=root&password=&useUnicode=true&characterEncoding=GBK
然后我页面上接收数据的代码如下<%@ include file ="verify.jsp"%>
<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*" %>
<%@ page import="java.text.*"%>
<%@ page import="java.util.List,java.util.ArrayList,java.util.Map,java.util.HashMap"%>
<%
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GBK");
%>
这个是开头的,
收到表单过来的数据
String note=new String(request.getParameter("note").getBytes("ISO_8859_1"),"big5");
用这种方法的之前一切OK,然后放到我朋友服务器上几天后就出现添加的数据是???的现象
我自己主观认为我本地机子OK的,可能是我朋友服务器上的问题。
但是一切并非尽人所料,张于,我自己本地机子上也出现了这种问题。
也算不出是什么原因导致,好像是突然之间的。

解决方案 »

  1.   

    这个要么是mysql支持中文的问题 要不然就是你转码的问题 
    我估计多半就是你转码的问题~
    你每次都转 从数据库里取出正常的汉字页转了一下 然后显示 自然就便乱码???了
    看看代码你转码的那块~
      

  2.   

    嗯,现在已经可以先不谈mysql支持中文的事了,事实上我已肯定不关mysql什么事。
    我测试了个最简单的数据<%
    String type=Tochar.getStr(request.getParameter("type"));
    if(type.equals("add")){
    int fatherid=Integer.parseInt(Tochar.getStr(request.getParameter("fatherid")));
    int grade=Integer.parseInt(Tochar.getStr(request.getParameter("grade")));
    String name=new String(request.getParameter("name").getBytes("ISO_8859_1"),"big5");
    String name1=request.getParameter("name");
    String name2=Tochar.getStr(request.getParameter("name"));
    String name3=new String(request.getParameter("name").getBytes("ISO_8859_1"),"gbk");
    %>
    <%=name%><br>
    <%=name1%><br>
    <%=name2%><br>
    <%=name3%><br>
    <%}%>结果是:
    ????
    穝竤舱
    ????
    ????说明和表单得到数据有关系,和数据库没什么大关系。但事实上我在之前,至少前天还是好好的,昨天忙点别的事,我不清楚。之前也是查了好久才查出办法了,不知道为什么现在这样了。大家帮帮我啦
      

  3.   

    ISO_8859_1中间是下滑_ 还是-?
      

  4.   

    我也遇到过这个问题,公司网站发布到服务器上头几天中文还没什么问题,过几天就全变成“???...”了。只是输出到xml文件中的文字是这样的,其它非xml数据则正常!后来没找到解决办法,就全改为不用xml保存数据了。。~~~~
    顶!!
      

  5.   

    你在jsp页面中加上
    <%@ page contentType="text/html; charset=GB2312" %>在xml中加上
    <?xml version="1.0" encoding="UTF-8"?>
      

  6.   

    不行,没什么大变化,事实上我要用繁体的,肯定要用big5这点是不会有错的。我想这样
    之前对的,如果现在要改,麻烦了,要改动地方太多了。
    如果有一次就能把代码全部弄得没用的办法,那理论上应该存在着一次能把代码修好的办法 我希望把这个修好方法找到来,可以的话,可以找到怎么破坏的方法就更好了,以后可以注意了。
      

  7.   

    kl嗯,好
    package net.action;
    import java.util.*;
    import java.sql.*;
    import java.io.*;
    /**
     * 系统名:     字符转换
     * 功  能:    字符转换
     * 作  者:    胡文虎
     */
    public class Tochar
    {
    public static String getStr(String str) {
        try{
             String temp_p=str;
             byte[] temp_t=temp_p.getBytes("ISO8859_1");
             String temp=new String(temp_t); return temp;
             }
        catch(Exception e){
              } //return "";
        if(str == null)
              return "";
        else
             return str;
     }
    }
      

  8.   

    也许unescapeValue()会对你有所帮助
      

  9.   

    我也看了一下还测试过了,你试一下这个吧
     public class Tochar
        {
            public static String getStr(String str)
            {
                try
                {
                    String temp_p = str;                Encoding encoder = Encoding.GetEncoding("big5");
                    byte[] temp_t = encoder.GetBytes(temp_p);
                    char[] tempchar = new char[encoder.GetCharCount(temp_t, 0, temp_t.Length)];
                    encoder.GetChars(temp_t, 0, temp_t.Length, tempchar, 0);
                    string temp = new string(tempchar);
                    return temp;
                }
                catch (Exception e)
                {
                } //return "";
                if (str == null)
                    return "";
                else
                    return str;
            }
        }
    还有一个转换代码        string unicodeString = "This string contains the unicode character Pi(\u03a0)";        Encoding ascii = Encoding.ASCII;
            Encoding unicode = Encoding.Unicode;
            
            byte[] unicodeBytes = unicode.GetBytes(unicodeString);
            byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
            char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
            ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
            string asciiString = new string(asciiChars);  
            Response.Write( unicodeString);
            Response.Write( asciiString);你自己试一下吧