中文出现乱码,求救!!!!!!

fanliuzhen 2004-10-19 11:19:37
我的一个页面,我用尽了办法,不知道怎么解决该问题:
<%@page contentType="text/html; charset=gb2312"%>
<%request.setCharacterEncoding("GB2312");%>
<%@page pageEncoding="GB2312"%>
这我都用了!!
请各位高手帮帮忙!!小弟不甚感激!!!
...全文
164 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyfish1231 2004-10-20
  • 打赏
  • 举报
回复
你接受的是什么编码?
rollinjsp 2004-10-20
  • 打赏
  • 举报
回复
这个嘛!非常简单了。
byte a[]=username.getBytes("ISO-8859-1");
username=new String(a);
这样就OK了,肯定没问题了!呵呵
zaneread 2004-10-20
  • 打赏
  • 举报
回复
什么大问题啊!字符转换
String str=new String(request.getParameter("str").getBytes("ISO-8859-1"),"gb2312");
Tasia 2004-10-20
  • 打赏
  • 举报
回复
java中的字符是用UTF-8的,而字节流在网络中传输是用ISO-8859-1,而我们想要看到的是GB2312或是GBK。
所以要这样做:
<%@ page contentType="text/html;charset=gb2312"%>
<%
String str = request.getParameter("ChineseString");
str = new String(str.getBytes("ISO-8859-1"), "UTF-8");
%>

转换后得到的str不论是在页面显示还是插入数据库都没有问题。
anewjavaboy 2004-10-20
  • 打赏
  • 举报
回复
包含表单的那个页面,你设定编码了吗?在那个页面设定编码才行!
zqj9899 2004-10-20
  • 打赏
  • 举报
回复
真是个大问题,去写个中文处理类呀
禽兽v5 2004-10-19
  • 打赏
  • 举报
回复
编码全转为gbk,因为gb2312有很多新字不支持。另外加上response编码和html代码中的编码。

<%
response.setContentType("text/html; charset=gbk");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
</head>
<body>
</body>
</html>
fanliuzhen 2004-10-19
  • 打赏
  • 举报
回复
显示乱码!!
lx_ccc 2004-10-19
  • 打赏
  • 举报
回复

<%@ page contentType="text/html;charset=gb2312"%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
request.setCharacterEncoding("GB2312");
%>
禽兽v5 2004-10-19
  • 打赏
  • 举报
回复
接收乱码还是显示乱码?

81,122

社区成员

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

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