程序需要发送http GET请求到服务器,请求的参数中包含了中文字符。程序中参数为UTF-8格式,且经过了UTF-8 URL编码再发送。使用的tomcat服务器,但服务器端后台程序中取到的参数的中文是乱码。
问题原因:
经过分析,应该是Tomcat在解析参数的时候没有使用正确的编码格式(UTF-8)去解码。
查看$TOMCAT_HOME/webapps/tomcat-docs/config/http.html这个说明文档,有如下说明:
URIEncoding:This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.
也就是说,如果没有设置URIEncoding, Tomcat默认是按ISO-8859-1进行URL解码,ISO-8859-1并未包括中文字符,这样的话中文字符肯定就不能被正确解析了。
解决办法:
修改Tomcat的Server.xml,在Connector标签中加上URLEncoding参数:
<Connector port="8080" maxThreads="150" minSpareThreads="25"
maxSpareThreads="75" enableLookups="false" redirectPort="8443"
acceptCount="100" debug="99" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="UTF-8"/>
改tomcat的server.xml文件(这里是解决含有中文的文件、图片的不能下载、显示的问题):
1 <Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
2 enableLookups="false" redirectPort="8443" acceptCount="100"
3 debug="0" connectionTimeout="20000"
4 disableUploadTimeout="true" [b]URIEncoding="UTF-8"[/b]/>
URIEncoding="UTF-8" 加上这句就可以识别中文文件了,也就是不光可以在jsp中显示中文,还可以下载显示。
解决Tomcat 不能下载带中文文件名的附件的方法
原创
©著作权归作者所有:来自51CTO博客作者mb6440a93307547的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
tomcat不能下载中文文件的问题
打开config/server.xml文件,如果没有
java 开发工具 HTTP tomcat eclipse -
PHP 上传的文件名乱码,下载excel出错(中文文件名)
中文文件名乱码,英文数字文件名都没问题相信你会遇到这样的问题,直接就来说说怎么解决:为什么呢?相信你会遇到这样的问题,直接就
编码 GBK UTF-8 PHP 文件名乱码 -
成功解决 Android 下载中文文件名(转)
tomcat6.x 服务器2、android虚拟器下载文件如下载服务器上文件: 测试.MP3下载路径:http://192.168.1.110:8080/mp3/测试.mp3解决办法:1.先在设置服务器编码:
服务器 tomcat android tomcat安装 文件名