中文乱码的问题2(急)

xcpxie011 2004-09-23 11:08:25
应用服务器:tomcat4
tomcat4所在操作系统:solaris(英文)
数据库服务器: orcle9 (ISO8859_1)
jsp(GB2312)

客户端操作系统:win2000(中文)
希望能够提供意见:
...全文
160 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangbow 2004-09-23
  • 打赏
  • 举报
回复
入库之前改变下编码就好了,直接对sql语句编码就成
sql=new String(sql.getBytes(),"8859_1");

1.s=new String(s.getBytes(),"iso-8859-1");
2.s=new String(s.getBytes(),"gb2312");
3.s=new String(s.getBytes("iso-8859-1"),"gb2312");
4.s=new String(s.getBytes("gb2312"),"iso-8859-1");
5.s=new String(s.getBytes("iso-8859-1"));
6.s=new String(s.getBytes("gb2312"));


尝试以上的方法之一!
页面中添加如下代码:
<%@ page contentType="text/html;charset=gb2312" %>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
linliangyi 2004-09-23
  • 打赏
  • 举报
回复
一楼的,你写错一行关键代码了,应该是:
byte[] temp_t=str.getBytes("ISO-8859-1");
temp=new String(temp_t);或temp=new String(temp_t,"GB2312");
viano 2004-09-23
  • 打赏
  • 举报
回复

你把所有的编码采用 gb2312 方式处理

jsp 页面:

<%@ page contentType="text/html; charset=gb2312" %>
<%request.setCharacterEncoding("gb2312");%>
zhujj81 2004-09-23
  • 打赏
  • 举报
回复
你是什么乱码啊?是插入数据库乱还是读出乱啊?

你先去看一下/etc/profile。命令:vi /etc/profile
加入:export LANG=zh
注意大小写哈。试试再说
drugon 2004-09-23
  • 打赏
  • 举报
回复
你最好是自己写一个中文转换的方法,特别是在从数据库中读出中文的时候。向数据库写信息的时候好象可以不转换的。
public String getStr(String str)
{
if(str==null) {
str="";
}
String temp="";
try
{
byte[] temp_t=str.getBytes("ISO-8859-1");
temp=new String(temp_t,"Big5");
str=temp;
}
catch(Exception e)
{
System.out.println("iso8859-1 error"+e);
return null;
}
return str;
}
xcpxie011 2004-09-23
  • 打赏
  • 举报
回复
我现在能从数据库中取到中文,
我的页面启用了<%@ page contentType='text/html; charset=GB2312' %>
这样可以使从后台来的数据以GB2312显示
还有一点当我 把后台来的数据人工转成GB2312显示出现乱码
转码代码:
private String codeString(String s){
String str=s;
String temp="";

try{
byte[] temp_t=str.getBytes("ISO-8859-1");
temp=new String(temp_t,"GB2312");
log.info("codeString = " + str);
return temp;
}
catch(Exception e)
{
log.error("e codeString = " + str);
return temp;
}
}

我怀疑orcle 数据库不是:ISO-8859-1
我怎样知道orcle 数据库的编码
yujiabian 2004-09-23
  • 打赏
  • 举报
回复
数据库的读写都应该进行编码的转换!要不然你写进去的是乱码,读出来的也是乱码!
fivesky 2004-09-23
  • 打赏
  • 举报
回复
楼上已经说得很全了 无非就这么几条

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧