zoukankan      html  css  js  c++  java
  • tomcat7.0在centos7下中文乱码问题解决汇总

    1. 系统级的中文设置

    Centos7跟之前的6和5安装的中文字符命令都不一样

    [root@iZ25bdzgev8Z ~]# locale  #查看当前系统的语言环境

    [root@iZ25bdzgev8Z ~]# yum -y install kde-l10n-Chinese  #安装中文语言包, yum源配置在阿里

    [root@iZ25bdzgev8Z ~]# yum reinstall glibc-common

    [root@iZ25bdzgev8Z ~]# LANG="zh_CN.UTF-8"

    2. 编辑server.xml文件, 红色字为添加的

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

                   connectionTimeout="20000" URIEncoding="UTF-8"  useBodyEncodingForURI=”true”

                   redirectPort="8443" />

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"   />

    3. 编辑项目下的数据库连接文件/var/lib/tomcat/webapps/myproject/WEB-INF/classes/config.properties, 红色字为添加的

      jdbc.url=jdbc:mysql://IP地址:3306/ myprojectDB?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true

    最后的    &useOldAliasMetadataBehavior=true      也可以不用添加

     

    4. 修改Web.xml文件  

    <servlet>

        <servlet-name>login</servlet-name>

        <servlet-class>cn.hncu.servlets.LoginServlet</servlet-class>

        <init-param>

            <param-name>character</param-name>

            <param-value>GBK</param-value>

        </init-param>

    </servlet>

    另外请求如果是 GET  的话,在代码中是很难做到不乱码的,因为大多数浏览器默认是使用本地字符集或UTF8,使用UTF8 时就好说了,但如果不使用UTF8 就五花八门了,在过滤器中使用 request.setCharacterEncoding() 只能用来处理 POST 请求,对 GET 则无效; 所以尽量使用POST请求

     

    4. 针对mysql进行字符设置

    mysql> show variables like 'character_set_database';

    mysql> alter database 库名 CHARACTER SET utf-8;

  • 相关阅读:
    JavaScript在web自动化测试中的作用
    Python使用Pandas高效处理测试数据
    git update-index --assume-unchanged忽略跟踪
    git reset三种模式
    Python Unittest根据不同测试环境跳过用例详解
    python ddt 实现数据驱动
    测试用例重要性暨动端测试用例设计总结
    jenkins执行selenium自动化测试浏览器不显示解决方法
    《过目不忘的读书法》 读书笔记
    memcached 学习
  • 原文地址:https://www.cnblogs.com/wxylog/p/6277139.html
Copyright © 2011-2022 走看看