Servlet中关于中文乱码

一、客户端请求服务器的数据有乱码
1.get方式请求
①修改tomcat/conf/server.xml,在<Connector> 标签中添加属性useBodyEncodingForURI="true"
②在获取请求数据之前,设置 request.setCharacterEncoding("utf-8");
2.post方式请求
在获取请求数据之前,设置 request.setCharacterEncoding("utf-8");

二、服务器返回给客户端的数据有乱码
response.setContentType("text/html; charset=utf-8");

原文地址:https://www.cnblogs.com/vieta/p/10846550.html