1.request乱码
原理:利用resp封装的setContentType
和setCharacterEncoding
方法把编码格式改成可以兼容中文的utf-8
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//转中文
req.setContentType("text/html");
req.setCharacterEncoding("utf-8");
}
2.response乱码
原理同上
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
resp.setCharacterEncoding("utf-8");
}