❶ java 中如何在 url 字元串找出中文字進行轉碼
url
中包含
「:、/」
是用來幹嘛的?
路徑?
如果有變數的話,建議還是單獨來
轉碼
,不要放進url然後把url全部轉碼。
❷ 用url傳漢字轉碼問題傳中文就報錯該怎轉碼啊
String s ="dfdf東方時代";
s=new String(s.getBytes("urf-8"),"iso-8859-1");
//2
s=java.net.URLEncoder.encode.decode(s,"utf-8");
❸ java url 轉碼
你這是從Servlet中取參然後在界面顯示是吧,JSP這個你設置的沒:<%@page pageEncoding="utf-8" contentType="utf-8" %>
以及request,response的設置:
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
希望對你能有所幫助。
❹ JAVA URLDecoder.decode轉碼失敗怎麼解決
編碼:java.net.URLEncoder.encode("測試","UTF-8");解碼:java.net.URLDecoder.decode("%E6%B5%8B%E8%AF%95%26%3Faaa","UTF-8");
❺ java轉碼後局部亂碼問題
問題給你解決了,看代碼
public class Test {
public static void main(String[] args) {
try {
String s = new String("中文測試局部亂碼問題2011中文測試上傳文件名亂碼問題.txt".getBytes(),
"UTF-8");
System.out.println(s);
s = java.net.URLDecoder.decode(s, "utf-8"); //utf8轉gbk
System.out.println(s);
Test convert = new Test();
byte[] fullByte = convert.gbk2utf8(s); //gbk轉utf8
String fullStr = new String(fullByte, "UTF-8");
System.out.println("string from GBK to UTF-8 byte: " + fullStr);
} catch (Exception e) {
e.printStackTrace();
}
}
public byte[] gbk2utf8(String chenese) {
char c[] = chenese.toCharArray();
byte[] fullByte = new byte[3 * c.length];
for (int i = 0; i < c.length; i++) {
int m = (int) c[i];
String word = Integer.toBinaryString(m);
StringBuffer sb = new StringBuffer();
int len = 16 - word.length();
for (int j = 0; j < len; j++) {
sb.append("0");
}
sb.append(word);
sb.insert(0, "1110");
sb.insert(8, "10");
sb.insert(16, "10");
String s1 = sb.substring(0, 8);
String s2 = sb.substring(8, 16);
String s3 = sb.substring(16);
byte b0 = Integer.valueOf(s1, 2).byteValue();
byte b1 = Integer.valueOf(s2, 2).byteValue();
byte b2 = Integer.valueOf(s3, 2).byteValue();
byte[] bf = new byte[3];
bf[0] = b0;
fullByte[i * 3] = bf[0];
bf[1] = b1;
fullByte[i * 3 + 1] = bf[1];
bf[2] = b2;
fullByte[i * 3 + 2] = bf[2];
}
return fullByte;
}
}
結果:
中文測試局部亂碼問題2011中文測試上傳文件名亂碼問題.txt
中文測試局部亂碼問題2011中文測試上傳文件名亂碼問題.txt
string from GBK to UTF-8 byte: 中文測試局部亂碼問題2011中文測試上傳文件名亂碼問題.txt
❻ java web程序路徑url URLEncoder.encode轉碼為什麼用GBK
通常情況下是不需要轉的,但有時候碰到一些get請求,路徑上帶中文件參數的,這就要轉了,這是IE機制的問題,轉一下比較保險
❼ java url中文轉碼問題
你這是從Servlet中取參然後在界面顯示是吧,JSP這個你設置的沒:<%@page pageEncoding="utf-8" contentType="utf-8" %>
以及request,response的設置:
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
❽ java url中有中文 傳到後台有亂碼 怎麼改 亂碼是
你這個問題真心不好辦,建議你把頁面編碼改為GBK編碼把。像樓上說的這些方法看似行得通,原理就是把utf-8轉為gbk然後再轉回utf-8,但那樣是不能解決問題的,試圖通過String newStr = new String(str.getBytes("gbk","utf-8"));辦不到的,結果是中文字元為奇數會出現最後一個字亂碼。我以前也曾碰到這個情況,最後還是把頁面統一編碼解決。