建议在jsp中汉字用espace刷换,在java中用
/*
* 转换码
*/
public static String unescape(String src){
StringBuffer tmp = new StringBuffer();
tmp.ensureCapacity(src.length());
int lastPos=0,pos=0,vpos=0; char ch;String strout="";
int srclength=src.length();
while (lastPos<srclength){
pos = src.indexOf("%u");
if (pos != -1){
//if (src.charAt(pos+1)=='u'){
ch = (char)Integer.parseInt(src.substring(pos+2,pos+6),16);
tmp.append(ch);
strout=strout+src.substring(0,pos)+ch;
lastPos = pos+6;
src=src.substring(pos+6);
//}
/*
else{
ch = (char)Integer.parseInt(src.substring(pos+1,pos+3),16);
tmp.append(ch);
lastPos = pos+3;
}
*/
}else{
//vpos=src.indexOf("%",lastPos);
if (pos == -1){
//tmp.append(src.substring(lastPos));
strout=strout+src;
lastPos=srclength;
}else{
tmp.append(src.substring(lastPos,vpos));
lastPos=vpos;
}
}
}
return strout;
}
转换,这样不管在什么web服务器下都能正常显示了
/*
* 转换码
*/
public static String unescape(String src){
StringBuffer tmp = new StringBuffer();
tmp.ensureCapacity(src.length());
int lastPos=0,pos=0,vpos=0; char ch;String strout="";
int srclength=src.length();
while (lastPos<srclength){
pos = src.indexOf("%u");
if (pos != -1){
//if (src.charAt(pos+1)=='u'){
ch = (char)Integer.parseInt(src.substring(pos+2,pos+6),16);
tmp.append(ch);
strout=strout+src.substring(0,pos)+ch;
lastPos = pos+6;
src=src.substring(pos+6);
//}
/*
else{
ch = (char)Integer.parseInt(src.substring(pos+1,pos+3),16);
tmp.append(ch);
lastPos = pos+3;
}
*/
}else{
//vpos=src.indexOf("%",lastPos);
if (pos == -1){
//tmp.append(src.substring(lastPos));
strout=strout+src;
lastPos=srclength;
}else{
tmp.append(src.substring(lastPos,vpos));
lastPos=vpos;
}
}
}
return strout;
}
转换,这样不管在什么web服务器下都能正常显示了
如果没有改这个配置,可能出现的情况就是,凡是在jsp中有做超链接传递中文字符的参数
传递到后台程序中就变成乱码了,你再从后台输出到前台,当然也是乱码了
把8080端口的配置加一个 useBodyEncodingForURI=true
就可以解决由于超链接传递中文字符出现的乱码问题了
“<!-- Define a non-SSL Coyote HTTP/1.1 Connector on the port specified during installation -->
<Connector port="8080" ..在这里加吗?...disableUploadTimeout="true" /> ”
可是我加上了useBodyEncodingForURI=true后网页打不开了,去掉后又能打开了 奇怪!
response.setCharacterEncoding("UTF-8")和
request.setCharacterEncoding("UTF-8")这两句如何加在JSP文件中?请给个小例子
这个系统的JSP文件大大小小有60多个,全部加上这些设置恐怕要累死,有没其他方法统一设置编码UTF8?