服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

彻底解决tomcat的页面提交时的中文问题

    <connector port="8080"
               maxthreads="150" minsparethreads="25" maxsparethreads="75"
               enablelookups="false" redirectport="8443" acceptcount="100"
               debug="0" connectiontimeout="20000"
               disableuploadtimeout="true" uriencoding="gbk"/>

就是在server.xml配置文件中加入 uriencoding=“gbk”这句话。

现归纳一下java中文问题,

1、页面中文显示,设置<meta http-equiv="content-type" content="text/html; charset=gbk">即可

2、response用流向页面输出中文,要设置response的字符集response.setcharaterencoding(”gbk”)
      如果使用printwriter输出中文,只要设置<meta http-equiv="content-type" content="text/html; charset=gb2312">

3、提交中文,对于tomcat就是使用开头的方法,对于weblogic,可以使用一个filter,在filter里面,设置request的字符集,request.setcharaterencoding(”gbk”)

4、如果用的不是jsp做输出页面,而是velocity,要在velocity.properties中设置
        velocimacro.library = webwork.vm, tigris-macros.vm
        input.encoding=gbk
        output.encoding=gbk
        default.contenttype=text/html; charset=gbk

5、万能转换,string str = new string(”中文”.getbytes(”gbk”),”iso-8859-1”);
        上面的方法把gbk字符输出到iso-8859-1字符集的页面

扫描关注微信公众号