javascript传值给servlet出现部分乱码问题

gaofengai999 2010-06-13 01:09:44
jsp中有一个按钮,触发JavaScript:onclick= "SelSubmit('<%=ig.getImgpath() %>','<%=ig.getImgname() %>')"
JavaScript中接收参数,并且跳转到servlet中:
function SelSubmit(type,typep)
{
document.myform.action= 'ImageServlet.do?method=submit2&type='+type+'&typep='+typep;

}
但是,在servlet中接收type和typep中时,会出现乱码:比如“6月7日”,会变成"6??日"
...全文
137 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xk1126 2010-06-13
  • 打赏
  • 举报
回复
escape()
sillyfish521 2010-06-13
  • 打赏
  • 举报
回复
escape()
l6801567 2010-06-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 qingmumu1985 的回复:]

前台jsp中js:
var tempAction='ImageServlet.do?method=submit2&type='+type+'&typep='+typep;
tempAction=encodeURI(tempAction);
tempAction=encodeURI(tempAction);//两次encodeURI
document.myform.acti……
[/Quote]

String typep=HttpServletRequest.getSession().getAttribute("typep");//不同的框架不同得到参数方式。
typep= new String(typep.getBytes("ISO-8859-1"),"UTF-8");解码,和上面唯一不同的地方
gaofengai999 2010-06-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 net_lover 的回复:]
document.myform.action= 'ImageServlet.do?method=submit2&type='+escape(type)+'&typep='+escape(typep);
[/Quote]

2楼的朋友,好像这样不行哟,跳转到servlet中后台会报错:java.io.CharConversionException: isHexDigit,而且,我也看网上,加了:
String type = request.getParameter("type");
type = java.net.URLDecoder.decode(type,"UTF-8");
System.out.println(type);
中间那句了呀~~~
qingmumu1985 2010-06-13
  • 打赏
  • 举报
回复
前台jsp中js:
var tempAction='ImageServlet.do?method=submit2&type='+type+'&typep='+typep;
tempAction=encodeURI(tempAction);
tempAction=encodeURI(tempAction);//两次encodeURI
document.myform.action=tempAction;
后台java代码:
String typep=HttpServletRequest.getSession().getAttribute("typep");//不同的框架不同得到参数方式。
typep= java.net.URLDecoder.decode(typep,"UTF-8");//Decoder.decode();解码
passself 2010-06-13
  • 打赏
  • 举报
回复
escape可以
孟子E章 2010-06-13
  • 打赏
  • 举报
回复
document.myform.action= 'ImageServlet.do?method=submit2&type='+escape(type)+'&typep='+escape(typep);

87,910

社区成员

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

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