Servlet-解决response响应中文乱码

public class ResoponseServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        
        //设置服务器字符集为utf-8
        resp.setCharacterEncoding("utf-8");

        //通过响应头。设置浏览器也使用utf-8
        resp.setHeader("Content-type","text/html;charset=UTF-8");

        PrintWriter writer = resp.getWriter();
        writer.write("lij李建超");
    }
}
上一篇:javaweb-14:Response重定向


下一篇:Servlet学习2