JNDI tomcat5 Mysql5 中文乱码

 <GlobalNamingResources>

    <!-- Test entry for demonstration purposes -->
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users -->
   
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
       description="User database that can be updated and saved"
           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />
     
      <Resource
    name="jdbc/huodong"
    auth="Container"
    type="javax.sql.DataSource"
    maxActive="5"
    maxIdle="3"
    username="root"
    maxWait="180"
    driverClassName="org.gjt.mm.mysql.Driver"
    password=""
    url="jdbc:mysql://localhost:3306/myDb?useUnicode=true&amp;characterEncoding=GBK"
    removeAbandoned="true" removeAbandonedTimeout="5" logAbandoned="true"
    testOnReturn="true" testWhileIdle="true"/>
  
  </GlobalNamingResources>

注意:url="jdbc:mysql://localhost:3306/myDb?useUnicode=true&amp;characterEncoding=GBK"

不要写成:url="jdbc:mysql://localhost:3306/myDb?useUnicode=true&characterEncoding=GBK"

注意:&amp;  & 的转义字符;在xml中写成上面那个,在java代码中写成下面的写法;

否则报:

Parse Fatal Error at line 213 column 91: The reference to entity "characterEncoding" must end with the ';' delimiter.
org.xml.sax.SAXParseException: The reference to entity "characterEncoding" must
end with the ';' delimiter.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Un
known Source)

还要在tomcat的 conf/server.xml 中修改如下类容:

<Connector port="80" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"/>

红色部分是添加的类容

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值