问题描述:用jsp写一个(模糊查询)搜索页面search.jsp ,在关键字中填写汉字(例如关键字:牛),搜结果正常,50条记录,
查询语句为:select * from product where 1=1 and name like '%顶%' or descr like '%顶%' limit 0 , 10现在想分页显示每页10条,当我第一页向第二页提交时(超链接href)没有结果,
查询语句为:select * from product where 1=1 and name like '%??%' or descr like '%??%' limit 10 , 10
但如果是英文就没有任何问题。问:解决上述问题的方法。
查询语句为:select * from product where 1=1 and name like '%顶%' or descr like '%顶%' limit 0 , 10现在想分页显示每页10条,当我第一页向第二页提交时(超链接href)没有结果,
查询语句为:select * from product where 1=1 and name like '%??%' or descr like '%??%' limit 10 , 10
但如果是英文就没有任何问题。问:解决上述问题的方法。
<%@ page contentType="text/html; charset=gb2312"%>
即使 reqeust.setCH....("GBK").String str = request.getParameter("key");
if (str == null) str = "";
else str = new String(str.getBytes("iso-8859-1"), "GBK");
但在加载页面时,已经为下一次的翻页留下了隐患--生成翻页的参数时,中文被自动转码了。
然后你用这个已经对中文转码的URL进行请求,而服务器端又没有进行再转码处理,所以出现了乱码。
最简单的解决办法,在服务器端加一个过滤器,对get方法提交来了请求参数进行转码。
当然,你也可以在页面翻页时用JS调用form的submit进行提交。
产生乱码的原因有很多,有两个页面的编码不一样,还有与容器编码不一致,以及post和get时会产生乱码,还有java服务端的乱码
注意看这条语句'%??%' 地方,说明字符集出错。
<%request.setCharacterEncoding("GBK");%>
加上这句解决post方式传递,要放在提交的前面
<Connector port="80" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"/>
<Connector port="80" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"/>