zoukankan      html  css  js  c++  java
  • java中文乱码问题解决

    1 处理乱码方式:

    1 连接数据库的时候  

             jdbc.properties:jdbc:mysql://localhost:3306/myproject?useUnicode=true&characterEncoding=utf8

    2 修改mysql配置文件my.ini/my.cnf       default-character-set=utf8

    3 修改tomcat中的配置文件server.xml改为

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

                   connectionTimeout="20000"

                   redirectPort="8443" URIEncoding="UTF-8"/>

    4 在web.xml配置spring过滤器

    <filter>

        <filter-name>char</filter-name>

        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

        <init-param>

             <param-name>encoding</param-name>

             <param-value>UTF-8</param-value>

        </init-param>

    </filter>

    <filter-mapping>

        <filter-name>char</filter-name>

        <url-pattern>/*</url-pattern>

     </filter-mapping>

    5 设置mysql字符集

          show variables like'character_set_%';

         把显示的character_set_**全都设置成utf8,即是:set character_set_serve='utf8'

                show variables like '%collation%';

         把显示的都设置成为如下:set collation_server='utf8_general_ci‘

    6.取值时HTtp(post)请求中的中文乱码

    在Servlet页面中 添加

    request.setCharacterEncoding("utf-8"); 

    user_name = request.getParameter("user_name") == null? "" : java.net.URLDecoder.decode(request.getParameter("user_name"), "UTF-8");

    7。前台返回????

    后台赋值:errorMessage = URLEncoder.encode("redis中没有该定期数据信息", "UTF-8").replace("+", "%20");

    前台取值:decodeURIComponent(errorMessage)

  • 相关阅读:
    php 获取文件的md5
    php 获取远程文件大小
    chrome 浏览器,大屏显示
    Mac 中Java项目打包上线
    如何在苹果M1芯片 (Apple Silicon) 上安装 JDK 环境
    Mysql 替换数据中的部分内容,比如迁移服务器,需要修改图片地址
    docker安装指定版本minio
    docker 查询镜像并删除
    docker 容器名称已存在
    docker 安装minio
  • 原文地址:https://www.cnblogs.com/lc93/p/7879147.html
Copyright © 2011-2022 走看看