用 request.getParameter() 得到的是乱码问题(谢谢高手指点)

maria728 2007-06-22 03:13:57
从一页面传过来一个参数 userId=${element.id} 但在Action 中打印出来是乱码

请问各位  这是什么问题   以前没遇到过,希望高手指点!

页面代码:

<logic:iterate id="element" name="account">
<tr>
<td>
<html:link href="update.do?userId=${element.id}"><font color="red">${element.id}</font></html:link>
</td>
<td>
<bean:write name="element" property="userName" ignore="true"/>
</td>
<td>
<bean:write name="element" property="userPass" ignore="true"/>
</td>
<td>
<bean:write name="element" property="description" ignore="true"/>
</td>
<td>
<h2 align="center"><a href="delete.do?userId=${element.id}"><font color="red">删除该用户</font></a></h2>
</td>
</tr>
</logic:iterate>




Action 中 :
String id = (String)request.getParameter("userId") ;
System.out.println("删除操作的测试 !" + id) ;

     id 打印出来是乱码
...全文
808 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
maria728 2007-06-22
  • 打赏
  • 举报
回复
谢谢  大家!

解决了
tdy1234 2007-06-22
  • 打赏
  • 举报
回复
req.setCharacterEncoding("GB2312"); 加上这一句看看
maria728 2007-06-22
  • 打赏
  • 举报
回复
我在struts web.xml中配置了个过滤器,

你说把传进来的参数转成 gbk 吗?    能不能帖上具体的代码!

谢谢
dilong95_9598 2007-06-22
  • 打赏
  • 举报
回复
URL中文参数传递问题
(1)确定JSP页面头部是否有:<%@ page contentType="text/html; charset=GBK" %>
(2)用这个转码:
String param= new String(request.getParameter("param").getBytes("ISO-8859-1"), "GBK");
(3)添加filter字符过滤器

(4)如果是通过"a.jsp?param=中文"传递参数,则需要:
a.在传参数之前先把参数进行转码:java.net.URLEncoder.encode(param);
取值用java.net.URLDncoder.decode(param);再转回中文
b.在你的Tomcat目录-->conf目录-->server.xml里找出这段:
<Connector
port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" <!--在里边加上这个参数-->URIEncoding="gb2312"
/>


zqrqq 2007-06-22
  • 打赏
  • 举报
回复
String id = (String)request.getParameter("userId") ;
id = new String(id .getBytes("ISO8859-1"),"GB2312");
试试看?
litestar 2007-06-22
  • 打赏
  • 举报
回复
在JSP有<%@ page language="java" contentType="text/html;charset=GBK"%>吗?
ID是什么类型?如果是中文,按下面的方法试试
String id = (String)request.getParameter("userId") ;
String id= new String(id.getBytes("ISO-8859-1"), "GBK");//
System.out.println("删除操作的测试 !" + id) ;
wxno1 2007-06-22
  • 打赏
  • 举报
回复
转码,转成gbk的,怎么转翻翻以前的,有贴子

81,094

社区成员

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

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