此种情况是在进行条件查询分页的时候,某个条件的值是汉字,点查询(第一次)为POST方式提交,不会出现乱码
当点下一页(第一次之后)为get提交,这时后台会出现中文乱码的问题,解决方案:
jsp:
- <form name="queryform" id="queryform" action="${path}/information_admlist.action" method="post">
- <input type="hidden" name="method" value="post">
- 标题:<input style="vertical-align:middle;" type="text" name="title">
- <input style="vertical-align:middle;" type="submit" value="查询">
- </form>
- <!--这里省略了首页等-->
- <a href="${path}/xxx.action?page=${pm.currentPage+1}&title=${title}">下一页</a>
Action:
- StringBuffer condition = new StringBuffer("");
- String method = request.getParameter("method");
- String title = request.getParameter("title");
- //提交方式post
- if(null != method && !"".equals(method) && method.equals("post")){
- if(null != title && !"".equals(title)){
- condition.append(" and im.title like '%").append(title).append("%'");
- //编码
- title = URLEncoder.encode(title, "UTF-8");
- }
- }else{//get
- if(null != title && !"".equals(title)){
- title = new String(title.getBytes("ISO-8859-1"),"UTF-8");
- condition.append(" and im.title like '%").append(title).append("%'");
- //编码
- title = URLEncoder.encode(title, "UTF-8");
- }
- }
本文介绍了解决在进行含有中文条件的分页查询时出现的乱码问题。通过在POST请求中对中文参数进行编码,并在GET请求中正确解码及重新编码的方式,确保了查询条件正确传递。

1万+

被折叠的 条评论
为什么被折叠?



