Servlet get和post乱码解决

最近在学习Servlet遇到了get和post中文乱码问题,看到好多网友也都写了一些解决方案,感觉都不是很灵活。

post

    修改前:

     resp.setContentType("text/html");

    修改后: resp.setContentType("text/html; charset=UTF-8");

   再加上 req.setCharacterEncoding("utf-8");

get:

    打开tomcat目录下conf目录中的server.xml文档

 修改前:   

   <Connector port="8080" protocol="HTTP/1.1"

   connectionTimeout="20000"
   redirectPort="8443" />

修改后:

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>

原文地址:https://www.cnblogs.com/Roysatm/p/4953529.html