出现中文乱码的主要原因是由于编码方式的不同。
1。在jsp页开头中加入一条语句:
<%@ page contentType="text/html;charset=gb2312" %>
2。对于从数据库中取出的数据:
String str=rs.getString("XXX");
byte [] bts = str.getBytes("8859_1");
String str1 = new String(bts,"GB2312");
1。在jsp页开头中加入一条语句:
<%@ page contentType="text/html;charset=gb2312" %>
2。对于从数据库中取出的数据:
String str=rs.getString("XXX");
byte [] bts = str.getBytes("8859_1");
String str1 = new String(bts,"GB2312");
Hello chh ¤p?j 你好
离
Hello chh 小姐 你好
还有距离这其中“小姐”是从html传过来的!
我的oicq是51404837,等您赐教好吗?
<%!
public 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 "null";
}
%>
在jsp页开头中加入一条语句:
<%@ page contentType="text/html;charset=gb2312" %>
在页面输出时,套上getStr(String)从数据库中取出的数据时不需要
另外,在jsp页开头中加入一条语句:
<%@ page contentType="text/html" %>
注意:别再要;charset=gb2312了。