通过传中文为什么显示乱码?

Yoursgulf 2003-09-29 03:43:35
哪伟大侠能够指点迷津???
...全文
292 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
zn7726 2003-09-30
  • 打赏
  • 举报
回复
写个ServletFilter,在doFilter中这样

HttpServletRequest req = (HttpServletRequest)request;
req.setCharacterEncoding("gb2312");
chain.doFilter(request, response);

再把这个filter map到/*

以后所有的中文问题就都解决了,可以不再考虑转中文的问题了

再有
字符集标示的大小写是有区别的,象下面这样写应该没问题的,至少在我这里可以(IDE - JDeveloper, Container - tomcat4.1.27)
new String(str.trim().getBytes("ISO8859_1"), "GBK"); //或者是"gb2312"
bruce_wang 2003-09-30
  • 打赏
  • 举报
回复
String str = request.getParameter("truename");
byte b[] = str.getBytes("ISO-8859-1");
str = new String(b);

试试这个
bruce_wang 2003-09-30
  • 打赏
  • 举报
回复
String str = request.getParameter("truename");
byte b[] = str.getBytes("ISO-8859-1");
str = new String(b);

试试这个。
Yoursgulf 2003-09-30
  • 打赏
  • 举报
回复
诸位大侠,还是不行,faint了
noratong 2003-09-29
  • 打赏
  • 举报
回复
我用的Tomact就没你那问题了。
代码差不多。
yg_zhang 2003-09-29
  • 打赏
  • 举报
回复
使用这个:
request.setCharacterEncoding("GBK");
flyshp 2003-09-29
  • 打赏
  • 举报
回复
你在客户端好像没控制中文的转换!!

<% %> 里都是在server 段执行的
flyshp 2003-09-29
  • 打赏
  • 举报
回复
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
Yoursgulf 2003-09-29
  • 打赏
  • 举报
回复
weblogic platform 7.0是我的server,就是一个很简单的测试,我贴一下大家看看
<%
String str="中文";
%>
<jsp:include page="/MyApp/test.jsp">
<jsp:param name="truename" value="<%=str%>"/>
</jsp:include>

test.jsp文件:
<%@ page contentType="text/html;charset=gb2312"%>
<%
String str= new String(request.getParameter("truename").getBytes("iso-8859-1"),"gb2312").trim();
out.println(str);
%>

就这样,还是显示乱码
flyshp 2003-09-29
  • 打赏
  • 举报
回复
你用什么做server ??
flyshp 2003-09-29
  • 打赏
  • 举报
回复
有没有可能你接收的参数本身就是乱码??

贴出源代码看看!!
Yoursgulf 2003-09-29
  • 打赏
  • 举报
回复
上面两种方法已经都试过了,均不可以,这就是最奇怪的原因!
noratong 2003-09-29
  • 打赏
  • 举报
回复
字符集的原因。
你在接收的页面用字符集转换方法,进行一下转换就可以了。
例如:
String str = new String(request.getParameter("str").getBytes("ISO-8859-1"),"GBK").trim();
subeggar 2003-09-29
  • 打赏
  • 举报
回复
在jsp文件头加上:
<%@ page contentType="text/html; charset=GB2312" %>

81,092

社区成员

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

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