编码 中文乱码

request的
get方式:tomcat 8 已经将get方式乱码问题解决了

  • post方式:会乱码
  • 解决:在获取参数前,设置request的编码request.setCharacterEncoding("utf-8");

 
response的
//获取流对象之前,设置流的默认编码:ISO-8859-1 设置为:GBK
// response.setCharacterEncoding("utf-8");

//告诉浏览器,服务器发送的消息体数据的编码。建议浏览器使用该编码解码
//response.setHeader("content-type","text/html;charset=utf-8");

合二为一就是
response.setContentType("text/html;charset=utf-8");













种一棵树最好的时间是十年前,其次是现在。
原文地址:https://www.cnblogs.com/islch/p/12790187.html