javaURI编码解码 1import java.io.UnsupportedEncodingException;
2/**
3 * url转码、解码
在线url网址编码解码4*/
5public class UrlUtil {
6private final static String ENCODE = "GBK";
7/**
8 * URL 解码
9 *
10*/
11public static String getURLDecoderString(String str) {
12 String result = "";
13if (null == str) {
14return "";
15 }
16try {
17 result = java.URLDecoder.decode(str, ENCODE);
18 } catch (UnsupportedEncodingException e) {
19 e.printStackTrace();
20 }
21return result;
22 }
23/**
24 * URL 转码
25*/
26public static String getURLEncoderString(String str) {
27 String result = "";
28if (null == str) {
29return "";
30 }
31try {
32 result = de(str, ENCODE);
33 } catch (UnsupportedEncodingException e) {
34 e.printStackTrace();
35 }
36return result;
37 }
38
39/**
40 *
41*/
42public static void main(String[] args) {
43 String str = "测试1";
44 System.out.println(getURLEncoderString(str));
45 System.out.println(getURLDecoderString(str));
46
47 }
48
49 }
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论