67,513
社区成员
发帖
与我相关
我的任务
分享
js:
window.location='search.do?method=doSearch&bid=0&title='+encodeURICompent('测试')
后台:
String title = new String(request.getParameter("title").getBytes("iso-8859-1"),"utf-8");
public static String ISOToUtf(String str) {
String s = "";
try {
s = new String(str.getBytes("iso-8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return s;
}
public static String ISOToGBK(String str) {
String s = "";
try {
s = new String(str.getBytes("iso-8859-1"), "GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return s;
}
public static String GBKToUTF(String str) {
String s = "";
try {
s = new String(str.getBytes("GBK"), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return s;
}
/**
* 判断是否汉字
*
* @param str
* @return
*/
public static String vd(String str) {
String ret = ISOToGBK(str);
char[] chars = ret.toCharArray();
boolean isGBK = false;
for (int i = 0; i < chars.length; i++) {
byte[] bytes = ("" + chars[i]).getBytes();
if (bytes.length == 2) {
int[] ints = new int[2];
ints[0] = bytes[0] & 0xff;
ints[1] = bytes[1] & 0xff;
if (ints[0] >= 0x81 && ints[0] <= 0xFE && ints[1] >= 0x40
&& ints[1] <= 0xFE) {
isGBK = true;
break;
}
}
}
if (isGBK) {
return ret;
} else {
return str;
}
}