在分页的时候请求页面search.jsp采用post方式提交,所以在search_result.jsp中第一页可以正常显示,但是想要翻页的时候,就会出现问题。 在Action中设置要翻页的URL为:pg.setLinkUrl(request.getContextPath()+"/search.do?method=doSearch&bid="+bid+"&type="+type+"&loginId="+loginId+"&title="+title);此时前台的请求页面显示为:http://localhost:8080/bbs/search.do?method=doSearch&bid=0&type=content&loginId=&title=测试&cpage=2,此时title为中文,怎样解决这种get方式下的乱码问题,我的项目全部都是用的utf-8编码。不想修改tomcat的server.xml,也就是添加一行URIEncoding="UTF-8",要不然服务器上不要发布就郁闷了。我试过很多方法了,filter中设置request.setCharacterEncoding("utf-8"),也不可以,盼求解决方法。
http://topic.csdn.net/u/20100126/18/a1c6a7d1-1d93-4b35-b14d-cd1398a1e363.html
那就set前encode,获取前decode
title = ???è??上面那个是第一页的结果显示时title,第二行就是第二页显示时title显示的值,还是没有办法正常显示。
String afterChangeStr = "";
try {
byte[] bt = str.getBytes("ISO8859_1");
afterChangeStr= new String(bt,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return afterChangeStr;
}}
js:
window.location='search.do?method=doSearch&bid=0&title='+encodeURICompent('测试')后台:
String title = new String(request.getParameter("title").getBytes("iso-8859-1"),"utf-8");
代码在程序里面没有问题就是插入到数据库就变成乱码!
请高手指点下
(oracle数据库)
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"
URIEncoding="gbk" />
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;
}
}