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"/>

红色部分是添加的类容

你可能感兴趣的:(apache,tomcat,mysql,xml,jdbc)