url后参数的转码与解码

import java.net.URLDecoder;
import java.net.URLEncoder;

String strTest = "?=abc?中%1&2<3,4>";
  strTest = URLEncoder.encode(strTest, "UTF-8");
  System.out.println(strTest);
  strTest = URLDecoder.decode(strTest,"UTF-8");
  System.out.println(strTest);

执行结果:

%3F%3Dabc%3F%E4%B8%AD%251%262%3C3%2C4%3E
?=abc?中%1&2<3,4>

jdk相关说明:

String java.net. URLEncoder.encode( String s, String enc) throws UnsupportedEncodingException

Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme. This method uses the supplied encoding scheme to obtain the bytes for unsafe characters.

Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilites.

Parameters:
s String to be translated.
enc The name of a supported character encoding.
Returns:
the translated String.
Throws:
UnsupportedEncodingException - If the named encoding is not supported
Since:
1.4
See Also:
URLDecoder.decode(java.lang.String, java.lang.String)
String java.net. URLDecoder.decode( String s, String enc) throws UnsupportedEncodingException

Decodes a application/x-www-form-urlencoded string using a specific encoding scheme. The supplied encoding is used to determine what characters are represented by any consecutive sequences of the form "%xy".

Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilites.

Parameters:
s the String to decode
enc The name of a supported character encoding.
Returns:
the newly decoded String
Throws:
UnsupportedEncodingException - If character encoding needs to be consulted, but named character encoding is not supported
Since:
1.4
See Also:
URLEncoder.encode(java.lang.String, java.lang.String)

使用URLEncoder、URLDecoder进行URL参数的转码与解码相关推荐

  1. URLEncoder和URLDecoder实现转码和解码

    在Java开发中,URL跳转经常遇到中文乱码问题.实际上,如果细心的话,我们会发现在访问网页时经常会在URL中看到一些16进制格式的字符串,如:http://xxx.com/s?w=%e7%bc 这其 ...

  2. Http请求url参数字符集

    http请求: 浏览器 -->服务器(tomcat应用服务器)--->应用 1,浏览器. url:浏览器默认采用UTF-8,对URL参数中非ASCII进行百分号编码(RFC3986&quo ...

  3. URLEncoder.encode(String url)和URLDecoder.decode(String url)

    1.http get请求本身是不支持中文的,例如下面的代码: form表单以Get方式提交 <form action="/jsp/deal.jsp" method=" ...

  4. URLEncoder 、URLDecoder 对 URL 编解码,HttpURLConnection 文件下载

    目录 URLEncoder  编码 URLDecoder 解码 URL 空格问题 与 HttpURLConnection 文件下载 URLEncoder  编码 1.public class URLE ...

  5. go url 参数编码和解码

    为什么80%的码农都做不了架构师?>>>    1 在做支付的时候会涉及到 url参数编码和解码,然后转换成自己想要的格式 app_id=2016073100129537&b ...

  6. jboss url路径_在JBoss的服务器端正确解码URL参数

    jboss url路径 我今天花了很多时间来弄清楚如何在运行在JBoss上的JSF应用程序中(使用JBoss 7 Final)强制正确解码编码的字符. 当您有例如通过URL传递中文字符时,就会发生此问 ...

  7. url中传递对象参数_在URL参数中传递复杂对象

    url中传递对象参数 假设您想传递原始数据类型,例如复杂的Java对象 java.util.Data,java.lang.List,泛型类,数组以及通过URL参数所需的所有内容,以便在页面加载后在任何 ...

  8. 在JBoss的服务器端正确解码URL参数

    我今天花了很多时间来弄清楚如何在运行在JBoss上的JSF应用程序中(使用JBoss 7 Final)强制正确解码编码的字符. 当您有例如通过URL传递中文字符时,就会出现此问题. 假设您有指点事件, ...

  9. 在URL参数中传递复杂对象

    假设您要传递原始数据类型,例如复杂的Java对象 java.util.Data,java.lang.List,泛型类,数组以及通过URL参数所需的所有内容,以便在页面加载后在任何网页上预设默认值. 共 ...

最新文章

  1. Windows7 网上邻居设置
  2. 设计模式学习之代理模式学习(一)
  3. 汇编题20200330
  4. mysql 整个数据库_mysql 整个数据库
  5. 这几个关乎我们一生教养的原则,每个人都应该知道。
  6. SQL.变量、运算符、if、while
  7. 想学人工智能从哪入手?
  8. 《用户网络行为画像》读书笔记(二)
  9. 数组指针 vs 指针数组
  10. Java程序员不得不会的124道面试题(含答案)
  11. 非线性可视化(2)非线性相图
  12. 神经网络 BPNN 机器学习 深度学习 拟合 时间序列 预测 分类
  13. 汇编语言---80386寄存器,GCC内联汇编语法
  14. 解除微信授权的html5网页,微信授权登录网页管理在哪里看?如何取消授权
  15. 计算机中¥符号按哪个键,电脑键盘符号快捷键大全 电脑键盘上每个键的作用?...
  16. 到底游戏中有什么是让你沉迷游戏的呢
  17. 报价单与贸易术语关系
  18. mysql 内存 优化_MySQL核心参数优化(内存优化)
  19. 六十六条经典禅语名句
  20. 5月28-29日规模化敏捷联合作战沙盘之乌托邦计划—成都站

热门文章

  1. Lawliet|C语言学习笔记5——循环结构
  2. QQ好友自定义头像不更新的解决办法(转)
  3. mySQL MAX与sum 连用_mysql – 在sql脚本中一起使用sum和max
  4. HOW TO:菜单名称有关操作
  5. 魅族春晚广告耗尽预算?继续约陌陌
  6. ios更新显示“已请求更新“但是没反应,最佳实践
  7. webpack版本和vue版本的冲突问题
  8. android按钮输出音频,android – 如何点击按钮播放声音
  9. 身体质量指数程序,入门写死的小程序项目
  10. 各类会议分析(Conference、workshop等,转载)