String trans(String chi)
{
String result = null;
try
{
result=new String(chi.getBytes("iso-8859-1"),"GBK");
}
catch(java.io.UnsupportedEncodingException e)
{
System.out.println (e.toString());
}
return result;
}
不知道行不行
{
String result = null;
try
{
result=new String(chi.getBytes("iso-8859-1"),"GBK");
}
catch(java.io.UnsupportedEncodingException e)
{
System.out.println (e.toString());
}
return result;
}
不知道行不行
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
request.setCharacterEncoding("gb2312");如果是jsp就加入:
<%@ page language="java" contentType="text/html;charset=GBK"%>
<%
request.setCharacterEncoding("gb2312");
%>因该可以解决的。呵呵,记得给我分哦
我就不在多说了
顶!!
不过要注意
我遇到过 request.setCharacterEncoding("gb2312")和jsp中的<%@ page contentType="text/html; charset=gb2312" language="java"%>同时用的话 从oracle数据中读出来的能正常显示 原来jsp的
汉字显示?? 我把request.setCharacterEncoding("gb2312")去了 就能全部正常显示
而你现在是想在JSP中读数据库,应该把你的转换函数改成这样才对:
result = new String(temp,"gb2312");
你的这句话少加了一个参数,所以等于没转换编码
对大家的两种建议,一是加request.setCharacterEncoding("gb2312"),二是,修改trans函数。
我想问的是如果采用第一种方法,是不是就不需要用trans函数了,同样,如果采取用trans函数,是不是就不用第一种方法了。
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">也可以,还有就是如果去掉<%@ page contentType="text/html; charset=gb2312" language="java"%>的话,不会影响到动态汉字数据的显示,而只会影响HTML页面的汉字。最后感谢大家参与我的问题的讨论。