2005/06/04 | 彻底解决Tomcat的页面提交时的中文问题
类别(计算机相关) | 评论(0) | 阅读(61) | 发表于 11:29
<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字符集的页面

---------------------------
阿炼:2005-06-04 中文问题解决
response.setContentType("text/html;charset=GB2312");
PrintWriter out = response.getWriter();
要注意一下两句的顺序
不然输出中文会变成问号
0

评论Comments