a链接传输中文,页面和后台处理方式

页面之间用a链接传递中文参数问题

<a type='button' class='button border-main' href='" + encodeURI("addmanage.jsp?id="+obj.coname) + "'><span class='icon-edit'></span>派货</a>

在使用页面用encodeURI对链接进行编码

    /*拿到前台传过来的id*/
	hreftext = window.location.href;
	console.log(hreftext)
	beginIndex = hreftext.indexOf("?");
	hreftext = decodeURI(hreftext.slice(beginIndex+4,hreftext.length)) 
	console.log(hreftext)
	document.getElementById('unname').value=hreftext;/*必须保证id在前面定义,否则找不到*/

接收页面使用decodeURI进行解码,就可以解决中文乱码问题了

 

后台servlet接收a链接中文

String coname=new String((request.getParameter("coname").getBytes("ISO-8859-1")),"gb2312");

如果还是乱码请把编码换一下,把gb2312换成utf-8

全部评论

相关推荐

04-27 08:59
常州大学 Java
牛客139242382号:《两门以上汇编语言》
点赞 评论 收藏
分享
在debug的柠檬精很迷人:好消息:现在HR挑三拣四 15年后 HR跪着求要简历 坏消息:被挑的是这代人,到时候求人的也是这代人。真好。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务