标签:乱码
在导出给银行的开户文件时出现乱码,银行要求的文件编码格式为gbk,但在本地服务器导出的编码格式始终为utf-8,通过new String(fileName.getBytes("ISO-8859-1"), "GBK");等方法始终没有办法解决。最后经过测试发现与web容器本身的编码格式有关。 最后修改tomcat的编码格式,顺利解决,具体如下:参考网址:http://www.blogjava.net/iduido/archive/2011/12/14/366364.html <?xml version=‘1.0‘ encoding=‘utf-8‘?> 2 <Server port="8085" shutdown="SHUTDOWN"> 3 4 <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 5 <Listener className="org.apache.catalina.core.JasperListener" /> 6 <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 7 <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> 8 <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 9 10 <GlobalNamingResources> 11 <Resource name="UserDatabase" auth="Container" 12 type="org.apache.catalina.UserDatabase" 13 description="User database that can be updated and saved" 14 factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 15 pathname="conf/tomcat-users.xml" /> 16 </GlobalNamingResources> 17 18 <Service name="Catalina"> 19 <Connector port="8088" protocol="HTTP/1.1" 20 connectionTimeout="20000" 21 redirectPort="8443" URIEncoding=‘GBK‘/> 22 23 <!-- Define an AJP 1.3 Connector on port 8009 --> 24 <Connector port="8809" protocol="AJP/1.3" redirectPort="8443" URIEncoding=‘GBK‘/> 25 26 <Engine name="Catalina" defaultHost="localhost"> 27 <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 28 resourceName="UserDatabase"/> 29 30 <Host name="localhost" appBase="webapps" 31 unpackWARs="true" autoDeploy="true" 32 xmlValidation="false" xmlNamespaceAware="false"> 33 34 35 </Host> 36 </Engine> 37 </Service> 38 </Server>
本文出自 “行者逐风” 博客,请务必保留此出处http://maoch.blog.51cto.com/3192119/1583920
标签:乱码
原文地址:http://maoch.blog.51cto.com/3192119/1583920