标签:author java.net == rgs private div import trace 转码
1 import java.io.UnsupportedEncodingException; 2 /** 3 * url转码、解码 4 * 5 * @author lifq 6 * @date 2015-3-17 下午04:09:35 7 */ 8 public class UrlUtil { 9 private final static String ENCODE = "GBK"; 10 /** 11 * URL 解码 12 * 13 * @return String 14 * @author lifq 15 * @date 2015-3-17 下午04:09:51 16 */ 17 public static String getURLDecoderString(String str) { 18 String result = ""; 19 if (null == str) { 20 return ""; 21 } 22 try { 23 result = java.net.URLDecoder.decode(str, ENCODE); 24 } catch (UnsupportedEncodingException e) { 25 e.printStackTrace(); 26 } 27 return result; 28 } 29 /** 30 * URL 转码 31 * 32 * @return String 33 * @author lifq 34 * @date 2015-3-17 下午04:10:28 35 */ 36 public static String getURLEncoderString(String str) { 37 String result = ""; 38 if (null == str) { 39 return ""; 40 } 41 try { 42 result = java.net.URLEncoder.encode(str, ENCODE); 43 } catch (UnsupportedEncodingException e) { 44 e.printStackTrace(); 45 } 46 return result; 47 } 48 49 /** 50 * 51 * @return void 52 * @author lifq 53 * @date 2015-3-17 下午04:09:16 54 */ 55 public static void main(String[] args) { 56 String str = "测试1"; 57 System.out.println(getURLEncoderString(str)); 58 System.out.println(getURLDecoderString(str)); 59 60 } 61 62 }
标签:author java.net == rgs private div import trace 转码
原文地址:https://www.cnblogs.com/the-wang/p/9049217.html