记录一下java开发中最常遇到的坑,关于前后端交互时,中文乱码问题。
有关存储中文的属性用encodeURIComponent修饰,则表示函数可把字符串作为 URI 组件进行编码
$.post('<%=request.getContextPath()%>/F_template_Action.do?method=getTemplateItemListData', {
templateId: templateId,
table:table,
pageIndex: 1,
tiaojianmap:encodeURIComponent(tiaojianmap),
pageSize: 16
}, function (data) {
在后台接受参数时:
String tiaojianmap=URLDecoder.decode(request.getParameter("tiaojianmap"), "UTF-8");
如果不行的话记得加上
// request.setCharacterEncoding("UTF-8");
// response.setCharacterEncoding("UTF-8");
response.setContentType("text/xml; charset=UTF-8");