Loading

请求响应乱码

post

响应编码

response.setContentType(“text/html;charset=UTF-8”);
response.setCharacterEncoding("UTF-8");

一般设置响应体用第一种

 get

请求编码  Tomcat-9会出现乱码

String name = request.getParameter("name");
byte[] bytes = name.getBytes("ISO8859-1");//打散:将name字符串按照原编码进行打散
name
=new String(bytes,"utf-8");//组装:将bytes字节数组按照指定字符编码进行组装,组装为String

優化
String name = request.getParameter("name");
name=new String(name.getBytes("ISO8859-1"),"utf-8");//组装:将bytes字节数组按照指定字符编码进行组装,组装为String

 

posted @ 2020-02-29 23:04  Rzk  阅读(145)  评论(0编辑  收藏  举报