zoukankan      html  css  js  c++  java
  • Java: Strut2 + MySql + Hibernate + ajax(jQuery)中文乱码解决办法

    Strut2 + MySql + Hibernate + ajax(jQuery)中文乱码解决办法:
    1. 网页页面使用utf-8
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">

    2. ajax默认使用utf-8传输数据, 但最好使用post, 不要使用get

    3. Struts2中使用UTF-8.
    3.1 在struts.properties中加上: struts.i18n.encoding=UTF-8
    [3.2 使用Filter: 从页面中传输数据到Struts2, 需要使用过滤器把数据在交给struts2前转换成utf-8的: http://stevieliu.blogchina.com/stevieliu/6223098.html]
    试过不使用3.2照常可以收到中文.

    4. 数据库也要使用utf-8, 在建表时设置好.
    http://imysql.cn/charset_tips

    5. hibernate.cf.xml配置文件中与数据库的连接符串也要标明使用的编码为utf-8: <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mlm?useUnicode=true&amp;characterEncoding=UTF-8</property>

    6: Tomcat也使用UTF-8
       6.1: Tomcat/bin/catalina.bat中开始部分(大概51行处)添加set CATALINA_OPTS=-Dfile.encoding=UTF-8
    或CATALINA_OPTS="$CATALINA_OPTS -Dfile.encoding=UTF-8"
       6.2: <Connector URIEncoding="utf-8" port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" />
    Eclipse启动Tomcat会修改Tomcat的运行编码环境,从终端启动的又是另一种编码环境,所以Tomcat的配置也要手动修改

    7: HttpServletResponse(request)也要设置编码:response.
    setCharacterEncoding("UTF-8");

  • 相关阅读:
    保持同步
    将Cent0S 7的网卡名称eno16777736改为eth0
    Linux系统各发行版镜像下载(2)
    Linux系统各发行版镜像下载
    ~/.ssh目录找不到解决方法
    克隆后虚拟机网络配置
    新建的linux虚拟机找不到eth0解决办法
    SecureCRT 7 注册码
    linux运维常用命令
    shell脚本实例(2)
  • 原文地址:https://www.cnblogs.com/Jghost/p/2973786.html
Copyright © 2011-2022 走看看