设置请求和响应的编码为utf-8
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
有时候设置请求和响应的编码为utf-8也不管用,那就再设置一下响应的类型
//设置请求和响应编码
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
//定义响应的类型是文本或者html
resp.setContentType("text/html");
如果输出的是jsp
就在jsp文件中头上加一句
<%@ page contentType="text/html;charset=UTF-8" %>