各位大哥,俺的程序在db中检索出中文数据。用 outputln("<td>" + getString() + "</td>") 显示在jsp页面上怎么是乱码?
用右键选择 中文编码 就可以正常现实了!
(如果在jsp中设置 UTF-8 或 GB2312的话,连右键选择 中文编码 也不能正常现实了)

解决方案 »

  1.   

    没看懂!
    俺的db 是mysql
      

  2.   

    在jsp开头加上
    <%@ page language="java" contentType="text/html;charset=GBK"%>
      

  3.   

    <%!String trans(String chi)
    {
                   String result = null;
                   byte temp [];
                   try
                   {
                           temp=chi.getBytes("iso-8859-1");
                          result = new String(temp);
                    }
                    catch(UnsupportedEncodingException e)
                    {
                            System.out.println (e.toString());
                    }
    return result;
    }
    %>
    调用这个函数试试!
      

  4.   

    各位大哥,俺的程序在db中检索出中文数据。用 outputln("<td>" + getString() + "</td>") 显示在jsp页面上怎么是乱码?
    用右键选择 中文编码 就可以正常现实了!
    (如果在jsp中设置 UTF-8 或 GB2312的话,连右键选择 中文编码 也不能正常现实了)
    ----------------------------------------------------------------------------你返回的大概是iso8859-1编码的东西!信息是对的,但是在E文编码不能显示中文,所以乱码,用右键选择 中文编码时 ,ie把他转换过了,可以正常显示;(如果在jsp中设置 UTF-8 或 GB2312的话,连右键选择 中文编码 也不能正常现实了:
       这个时候你把iso8859-1的当成gb2312处理,当然是乱码了,信息错误了,无论如何都是乱码
    outputln("<td>" + getString() + "</td>") 换成: 
    String temp=getString() ;
    temp=new String(temp.getBytes("iso8859-1"),"gb2312");
    outputln("<td>" + temp+ "</td>") ;并且在jsp中设置GB2312
      

  5.   

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>如果这两个都有的话,我暂时就不懂了
      

  6.   

    谢谢  jihanzhong(逍遥) 以及其他人的帮助。结贴散分!