Servlet乱码解决

后端收前端

1.post乱码

可以通过 request.setCharacterEncoding("utf-8");  这样在后端可以接收中文

2.get乱码(手动解决)

可以通过 

String para = request.getParameter("name");
String para2 = new String(para.getBytes("iso-8859-1"),"utf-8");

后端向前端输出中文

第一步:设置浏览器接收的码表。两种方法

//设置response查询的码表
        //response.setCharacterEncoding("UTF-8");
        
        //通过一个头 Content-Type 告知客户端使用何种码表
        //response.setHeader("Content-Type", "text/html;charset=UTF-8");
        
//        这句与上句等价,开发中只用写这句,tomcat自动设置第一句
        response.setContentType("text/html;charset=UTF-8");
原文地址:https://www.cnblogs.com/qlqwjy/p/7551424.html