zoukankan      html  css  js  c++  java
  • web开发中遇到的乱码问题

      相信大家在web开发中会遇到乱码问题,有页面乱码,请求乱码,数据库乱码等等,下面我这边列举一下针对不同情况的乱码的解决方案:

    1.相应数据乱码:

    //只需要在后台接口方法里面的开头写上这样一句话指定响应字符集是utf-8
    response.setContentType("text/html;charset=utf-8");

    2.请求数据乱码:

      ①.Get请求:

        第一种方式 tomcat默认的字符集是iso8859-1,可以手动将其转换为想要的字符集,手动转码;

        第二种方式,配置过滤器,使用Filter;

        第三种方式 ,直接修改tomcat配置

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

      ②post请求:

    request.setCharacterEncoding("utf-8")

    3.数据库乱码:

    jdbc: useUnicode=true&characterEncoding=utf-8
    建表  create table xxx()engine=Innodb default charset=utf-8

    4.html文件

    <meta charset="utf-8">

    5.项目编码设置成utf-8

      

  • 相关阅读:
    MongoDB理解
    jQuery+Ajax+PHP实现异步分页数据显示
    PHP设计模式四:适配器模式
    PHP设计模式三:原型设计模式
    Event Managers
    NetAdvantage
    英语
    CA1060
    DateTime和DateTime2
    宿主进程 vshost.exe
  • 原文地址:https://www.cnblogs.com/MrXiaoAndDong/p/RandomCode.html
Copyright © 2011-2022 走看看