发布:2021/7/22 15:29:31作者:管理员 来源:本站 浏览次数:1290
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相关说明:
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.
String
to be translated.
String
.
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.
String
to decode
String
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4