把这两段加上,就ok了
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<head>
<title>ss</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
如果是英文系统
要进行编码转换的
在bean里写函数,调用就可以了
//处理中文问题的自定义函数
public String getcn(String str)//取、
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("GBK");
String temp=new String(temp_t,"ISO8859_1");
return temp;
}
catch(Exception e)
{ return "null";}
}
public String setcn(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 "null";}
}
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<head>
<title>ss</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
如果是英文系统
要进行编码转换的
在bean里写函数,调用就可以了
//处理中文问题的自定义函数
public String getcn(String str)//取、
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("GBK");
String temp=new String(temp_t,"ISO8859_1");
return temp;
}
catch(Exception e)
{ return "null";}
}
public String setcn(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 "null";}
}
然后在第一个resquest.getParameterq()前加request.setCharacterEncoding("GB2312");2.将 ' 替换成""
加个方法:
<%!public getStr(String str) throws Exception
{
String temp=str;
byte[] temp_p=temp.getBytes("ISO-8859-1");
return new String(temp_p,"GBK");;
}
%>
然后在插入数据库之前将有中文的变量用这个方法将变量转换一下:
String text=null;
if(request.getParameter("text")!=null&&request.getParameter("text")!="")
{
text=getStr(request.getParameter("text"));
}
String temp=str;
byte[] temp_p=temp.getBytes("ISO-8859-1");
return new String(temp_p,"GBK");
然后在输出看是否是乱码。
如果不是乱码了,就将数据插入数据库;
如果在数据库中显示为乱码,那么你在看一下数据库的语言设置,应该是数据库的原因了。
但是在网页上输出的事乱码!
若是在网页上输入,则数据库中的也是乱码!
这是怎么回去?