URL编码解码

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
/**
 * URL处理工具
 * @author RuiLin.Xie - xKF24276
 *
 */
public class UrlUtil
{

	/**
	 * URL编码
	 * @param url
	 * @return
	 */
	public static String encode(String url, String enc)
	{
		String s = null;;
		try
		{
			s = URLEncoder.encode(url, enc);
		}
		catch (UnsupportedEncodingException e)
		{
			e.printStackTrace();
		}
		return s;
	}
	
	/**
	 * URL解码
	 * @param url
	 * @return
	 */
	public static String decode(String url, String enc)
	{
		String s = null;
		try
		{
			s = URLDecoder.decode(url, enc);
		}
		catch (UnsupportedEncodingException e)
		{
			e.printStackTrace();
		}
		return s;
	}
}

你可能感兴趣的:(java,.net)