作者:rz白雪 | 来源:互联网 | 2023-09-16 09:02
防止出现乱码OverrideprotectedvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)t
防止出现乱码
@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// //获取流对象之前,设置流的默认编码:ISO—8859-1 设置为: GBK
// response.setCharacterEncoding("utf-8");
//
// //告诉浏览器,服务器发送的消息体数据的编码。建议浏览器使用该编码解码
// response.setHeader("content-type", "text/html;charset=utf-8");//简单的形式,设置编码response.setContentType("text/html;charset=utf-8");//1.获取字符输出流PrintWriter pw = response.getWriter();//2.输出数据
// pw.write("hello response
");pw.write("你好 response
");}