encodeURIComponent编码后java后台的解码
来源:互联网 发布:网络视频会议系统 编辑:程序博客网 时间:2024/05/19 05:05
出现JavaScript用encodeURIComponentt编码后无法再后台解码的问题。
原来他是这样写的:
var url="<%=path %>/download.do?dispatch=downloadTeachingVideo";
window.location=url+"&location="+encodeURIComponent(rows[0].location);
java处理的代码为:
location=java.net.URLDecoder.decode(location,"UTF-8");/*需要处理异常*/
咋一看觉的没问题啊,一编一解的,应该可以了。但还是出现了乱码。
后来网搜资料,发现原来在对后台java程序里的location赋值的时候,本身已经使用了一次解码,不过解码的结果依然不对。所以我们可以在页面上进行两次编码操作,这样后台自动的那次就可以抵消掉一次,然后在使用
location=java.net.URLDecoder.decode(location,"UTF-8");/*需要处理异常*/进行一次解码就好了。
正确的代码:
JavaScript:
var url="<%=path %>/download.do?dispatch=downloadTeachingVideo";
window.location=url+"&location="+encodeURIComponent(encodeURIComponent(rows[0].location));
java:
location=java.net.URLDecoder.decode(request.getParameter("location"),"UTF-8");/*需要处理异常*/
另外还有一种方法是JavaScript进行一次编码,后台java处理时换种想法就好了:
java代码:
String s = new String(request.getParameter("location").getBytes("ISO8859-1"), "UTF-8");
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台的解码
- encodeURIComponent编码后java后台解码乱码的解决
- HTML encodeURIComponent编码后java后台的解码
- js中使用encodeURIComponent编码url后java后台的解码
- encodeURIComponent编码与解码--java
- encodeURIComponent传入后台解码
- mvc表单Form提交
- Documentation/console/console.txt
- 黑马程序员---Java基础学习笔记(IO-前篇)
- SQL Server 2005 加密(安全性:非对称密钥、证书、对称密钥)
- Android 短按耳机键暂停/播放FM功能的实现
- encodeURIComponent编码后java后台的解码
- Python distribution打包&安装流程
- Android Message和obtainMessage的区别
- UVA 571(数论)
- Linux系统安装后的基础优化-基于CentOS(5.8/6.4)
- INSTALL_FAILED_DEXOPT 解决
- TCP/IP网络编程的四书五经
- struct inode 和struct file
- linux驱动子系统--驱动模型