jsp:
$.ajax({
type: "POST",
url: url, //代码数据
async:false,
data:{"id":id,"flowsta":flowsta,"username":username},
error:function(){
parent.$.jBox.tip("与数据库连接失败!", 'info');
},
success:function() {
parent.$.jBox.tip("操作成功!", 'info');
reloadNotPage();
}
});
action:
String username=req.getParameter("username");
username=new String(username.getBytes("GBK"), "UTF-8");
最后结果只有一半是乱码:
刘西??
后面问号是乱码,这是什么情况
解决请求参数乱码的问题,最好的方式是使用拦截器,那么后台 Controller 中无需任何专转码处理。
1、jsp 页面统一编码类型为 utf-8 :
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
2、tomcat 服务器 server.xml 配置 URIEncoding 配置为 UTF-8
3、在 web.xml 中添加编码拦截器,设置请求的字符编码和响应的字符编码。
Controller方法中加上 如下
response.setContentType("text/html;charset=UTF-8");//这些设置必须要放在getWriter的方法之前,
response.getWriter().print(JSON.toJSONString(ulist));