Servlet乱码问题解决

  1. 使用String重新进行编码

    String name = new String(name.getBytes("ios-8859-1"),"utf-8")
    
  2. get请求乱码

    request.setCharacterEncoding("utf-8");
    

    在server.xml中添加属性useBodyEncodingorURI=true

  3. post请求乱码

    request.setCharacterEncoding("utf-8");
    
  4. response乱码

    response.setCharacterEncoding("utf-8");
    
    response.setContentType("text/html;charset=utf-8")
    
posted @ 2020-04-04 13:02  striver-sc  阅读(80)  评论(0编辑  收藏  举报