网址的转码UrlEncode与URLDecoder

网址的转码UrlEncode与URLDecoder


package com.hejingzhou;

<span style="font-size:18px;">import java.io.UnsupportedEncodingException;

public class UrlEncode {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String url = "邢台";
		String url$ = "%E9%82%A2%E5%8F%B0";
		String url_result = null;
		String url$_result = null;
		//编码
		try {
			url_result = java.net.URLEncoder.encode(url,"UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.print("编完码后    "+url_result);
		System.out.print("\n\n\n");		
		//解码
			try {
				url$_result = java.net.URLDecoder.decode(url$, "UTF-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("解完码后    "+url$_result);
	}

}</span>


打印结果:

编完码后    %E9%82%A2%E5%8F%B0




解完码后    邢台

你可能感兴趣的:(网址的转码UrlEncode与URLDecoder)