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)

  • 相关阅读:
    opencv3.2.0形态学滤波之腐蚀
    Ubuntu下卸载QT5.7.1再重装
    opencv3.2.0形态学滤波之膨胀
    Direct3D中的绘制
    绘制流水线
    初始化Direct3D
    VS2012添加对DirectX SDK中需要文件的引用
    ASCII,Unicode 和通用方式
    对话框访问的7种方式【孙鑫老师教程】
    函数指针
  • 原文地址:https://www.cnblogs.com/lc93/p/7879147.html
Copyright © 2011-2022 走看看