解決中文拼接在url後的亂碼問題--gbk 在url上的編碼
URLEncoder.encode(temp,"UTF-8");
URLDecoder.decode(temp, "UTF-8");
public static void main(String[] args) throws UnsupportedEncodingException {
// TODO Auto-generated method stub
String temp = "http://local:9080/epg/2y四川tt成都";
temp = URLEncoder.encode(temp,"UTF-8");
System.out.println(temp);
temp = URLDecoder.decode(temp, "UTF-8");
System.out.println(temp);
//下面這個是測試,如果兩次編碼是否會出現亂碼,驗證結果是不會
temp = URLDecoder.decode(temp, "UTF-8");
System.out.println(temp);
}
結果如圖:
http%3A%2F%2Flocal%3A9080%2Fepg%2F2y%E5%9B%9B%E5%B7%9Dtt%E6%88%90%E9%83%BD
http://local:9080/epg/2y四川tt成都
http://local:9080/epg/2y四川tt成都