`

get提交url中文参数乱码问题完美版

JSP 
阅读更多

 此种情况是在进行条件查询分页的时候,某个条件的值是汉字,点查询(第一次)为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");
	}
}

 

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics