这段代码必须在获取response对象之前设置
response.setContentType("text/html;charset=utf-8");
错误示范:
PrintWriter writer = resp.getWriter();
//设置请求和相应编码
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
应改为:
//设置请求和相应编码
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
PrintWriter writer = resp.getWriter();