首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

解决地址栏传汉语出现乱码 tomcat配置文件解决方案

2012-09-23 
解决地址栏传中文出现乱码 tomcat配置文件解决方案在写Java Web 程序时。jsp地址栏传中文时,在Action接收时

解决地址栏传中文出现乱码 tomcat配置文件解决方案

在写Java Web 程序时。jsp地址栏传中文时,在Action接收时,经常会出现乱码问题。

程序的解决办法是:

1.在地址栏传值时,先把值用js 函数encodeURI编码。用法:encodeURI('许国柱') 如:http://www.ih99.com/reg.do?name=encodeURI('许国柱')

2.Action接收时,再进行转义。String name = new String(request.getParameter("name").getBytes('iso8859-1'),"utf-8")

?

tomcat配置文件解决办法是:

打tomcat进的server.xml配置文件把

<Connector port="8080" protocol="HTTP/1.1"
?????????????? connectionTimeout="20000"
?????????????? redirectPort="8443" />

?

?

<Connector port="8080" protocol="HTTP/1.1"
?????????????? connectionTimeout="20000"
?????????????? redirectPort="8443" useBodyEncodingForURI="true" URIEncoding="UTF-8"/>

添加 useBodyEncodingForURI="true" URIEncoding="UTF-8" 这两个参数即可。

热点排行