form提交数据到servlet中,确保从前端传输到后端接收都为utf-8
前端
<head>
<meta charset="utf-8">
</head>
确保为utf-8
后端
public class LocationServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//设置request编码格式
request.setCharacterEncoding("utf-8");
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request,response);
}
}
这里的request.setCharacterEncoding("utf-8");确定后端接收的数据也为utf-8,保证前后编码一致。
若是tomcat输出的时候都是乱码,则要去tomcat的安装地去
将里面的改好