前端传到后端的中文乱码问题
目录
前端传到后端的中文乱码问题
在用mybatis+spring+jsp往数据库插入数据时发现插入的中文出现乱码
通过debug发现浏览器页面传入时中文格式正常
但后端从request中拿数据时出现乱码
String name = request.getParameter("name");
问题解决:
排查了mybatis和mysql的编码格式设置都正确
于是猜测是因请求的编码格式没有设置成utf-8导致
request.setCharacterEncoding("utf-8");
在controllor层设置浏览器发送请求的编码格式