问题描述:jsp编码gbk(第三方提供),spring过滤器编码utf-8,struts要得到准确的中文。
解决方案:
重写过滤器,把接收第三方jsp的action用gbk过滤,其他action用utf-8过滤。
不过如果传过来已经是乱码,那么还得转码。当然转码是需要判断是否是乱码。
判断乱码的代码:
解决方案:
重写过滤器,把接收第三方jsp的action用gbk过滤,其他action用utf-8过滤。
不过如果传过来已经是乱码,那么还得转码。当然转码是需要判断是否是乱码。
判断乱码的代码:
public static boolean garbled(String str) {
char ws[] = new char[] { '?' };
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
for (int j = 0; j < ws.length; j++) {
char v = ws[j];
if (c == v) {
return false;
}
}
if ((int) c == 0xfffd) {
return false;
}
}
return true;
}