URLEncoder和URLDecoder加密解密

URLEncoder和URLDecoder加密解密

 

 

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

/**
 * URLEncoder和URLDecoder
 * 解决URL字符串中参数特殊字符的传递问题!
 */
public class URLEncoderOrURLDecoder {
	public static void main(String[] args) {
		String str = "juapk.com?userName=轻描@淡写.%*";
		try {
			String strEncode = URLEncoder.encode(str, "UTF-8");
			String strDecode = URLDecoder.decode(strEncode, "UTF-8");
			System.out.println("原始字符串:" + str);
			System.out.println("URLEncoder.encode加密:" + strEncode);
			System.out.println("URLDecoder.decode解密:" + strDecode);
		} catch (Exception e) {
			e.getStackTrace();
		}
	}
}

 

 

输出日志:

 

 

原始字符串:juapk.com?userName=轻描@淡写.%*

URLEncoder.encode加密:juapk.com%3FuserName%3D%E8%BD%BB%E6%8F%8F%40%E6%B7%A1%E5%86%99.%25*

URLDecoder.decode解密:juapk.com?userName=轻描@淡写.%*

 

你可能感兴趣的:(decode)