var label = $("#label").val();
var url = contextPath + "catentry/search.action?catGroupId="
+id+"&searchType=search2"+"&label="+label;
$.post(url,function(data){
$("#searchFormArea").html(data);
});
}
label传到后台中文乱码,加上处理后如下:
var searchCatentry = function(id){
var label = $("#label").val();
var url = contextPath + "catentry/search.action?catGroupId="
+id+"&searchType=search2"+"&label="+encodeURIComponent(label);
$.post(url,function(data){
$("#searchFormArea").html(data);
});
}
后台:if(request.getParameter("label") != null && !"".equals(request.getParameter("label")) ){
String showLabel = request.getParameter("label").trim();
showLabel = this.decodeStringByUtf8(showLabel);
request.setAttribute("label", showLabel);
}
this.decodeStringByUtf8(showLabel);函数如下:
/**
* 以UTF8解字符编码,防止中文乱码
* @author raoanhui
*/
final protected String decodeStringByUtf8(String s) {
if (StringHelper.isEmpty(s))
return s;
try {
return URLDecoder.decode(s, "utf-8");
} catch (Exception e) {
e.printStackTrace();
return s;
}
}
以上几步就可以解决中文乱码。