你应该在每个jsp程序前面加上
<%@page contentType="text/html; charset=gb2312"%>或者
<%@page contentType="text/html; charset=GBK"%>
这是必须的。
否则肯定出问题!
<%@page contentType="text/html; charset=gb2312"%>或者
<%@page contentType="text/html; charset=GBK"%>
这是必须的。
否则肯定出问题!
import java.io.*;public class contcode
{
public String descode = "";
public String srccode = "";
public String getnewcode(String sourcestr)
{
String tmp;
try
{
if(srccode.equals("") && descode.equals(""))
{tmp = sourcestr;}
else if(srccode.equals(""))
{tmp = new String(sourcestr.getBytes(),this.descode);}
else
{tmp = new String(sourcestr.getBytes(this.srccode),this.descode);}
}
catch(Exception e)
{
tmp = this.descode + "->>" + this.srccode;
}
return(tmp);
}
public String getnewcode(String sourcestr,String scode,String dcode)
{
String tmp;
try
{
if(scode.equals("") && dcode.equals(""))
{tmp = sourcestr;}
else if(scode.equals(""))
{tmp = new String(sourcestr.getBytes(),dcode);}
else
{tmp = new String(sourcestr.getBytes(scode),dcode);}
}
catch(Exception e)
{
tmp = dcode + "->>" + scode;
}
return(tmp);
}}
如果数据库中中文正确,文件头上加:
<%@ page contentType="text/html;charset=gb2312" %>
就可以了
如果数据库中的不正确就要在写进数据库前用String str=new String(str.getBytes("ISO8859_1"),"gb2312")转换一下