回 帖 发 新 帖 刷新版面

主题:为什么从数据库中取出汉字为乱码?而且只在一个页面发现这种情况

<%@ page language="java" contentType="text/html;charset=gb2312"%>
  .......
 .......
while(rs.next())
    {
      ID=rs.getInt("ID");
      title=rs.getString("title");
      title=new String(title.getBytes("iso-8859-1"),"gb2312");
      content=rs.getString("content");
      content=new String(content.getBytes("iso-8859-1"),"gb2312");
      date1=rs.getString("date1");
}
<%=title%><%=content%>输出乱码

回复列表 (共3个回复)

沙发

你试试这样写
while(rs.next())
    {
      ID=rs.getInt("ID");
      title=rs.getString("title");
      title=new String(title.getBytes("8859_1"));
      content=rs.getString("content");
      content=new String(content.getBytes("8859_1"));
      date1=rs.getString("date1");
}

板凳

可能是将网页上内容content保存到数据库中时,要先要编码转换,content=new String(content.getBytes("8859_1"));

3 楼

当输出时不用转换

我来回复

您尚未登录,请登录后再回复。点此登录或注册