中文乱码解决的4种方式
目前收集到4中方法,中文传参一documentPath为例:
1.改为form方式提交,不用超链接方式提交,用form方式传参指定不乱码。
2.通过encodeURI(encodeURI(checkText))提交,java代码中用URLDecoder.decode解码:
<script>
function download(documentPath){
var url = "<c:url value='/product/download.action?documentPath='/>"+documentPath;
url = encodeURI(encodeURI(url));
window.location.href=url;
}
</script>
java代码中取中文:
String documentPath = (String) request.getParameter('documentPath');
documentPath = URLDecoder.decode(documentPath,"utf-8");
3.修改tomcat的server.xml中的connector,添加URLEncoding="UTF-8"
4.中文从java中传到jsp再通过url传到java:
java中编码:URLEncoder.encode(URLEncoder.encode("传递的中文","utf-8"));
java中解码码:URLDecoder.decode(request.getParameter('documentPath'),"utf-8");
上一篇: 在datagrid中应用自定义的字体
下一篇: Spring中实现定时任务
推荐阅读
-
linux下mysql乱码问题的解决方案
-
Three.js使用THREE.TextGeometry创建三维文本中文乱码的问题如何解决?
-
使用逐鹿工具箱时文字显示为乱码的解决方法介绍
-
Linux下程序库Ncurses显示中文乱码的解决方法
-
使用php实现下载生成某链接快捷方式的解决方法
-
android studio错误: 常量字符串过长的解决方式
-
快速解决pandas.read_csv()乱码的问题
-
解决pandas read_csv 读取中文列标题文件报错的问题
-
让sql2005运行在独立用户下出现 WMI 提供程序错误的解决方式
-
chrome内核浏览器不能翻译成中文该怎办? 谷歌浏览器无法翻译的解决办法