flex URLRequest传中文参数到后台乱码问题解决方法

转:http://liyanjie918.blog.163.com/blog/static/2022729020128261252258/

使用URLRequest时经常需要传参数,如果参数中包含中文传到后台经常出现乱码,

解决办法一:将参数进行编码,在后台进行解码就可以了,实例代码:
flex端:
var urlRequest:URLRequest;
var url:String = "******";
var url:String = encodeURI(fullPath);
urlRequest = new URLRequest( url+"downExcel?fullPath=" + fullPath);
 
java 端:
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  ......
  String fullPathName = new String(req.getParameter("fullPath").getBytes("ISO-8859-1"),"UTF-8");
  ......

}
此种方法有局限性,如果在tomcat设置的编码格式会导致在此乱码。
解决办法二:将前台参数进行编码,指定tomcat编码格式,实例代码:
var urlRequest:URLRequest;
var url:String = "******";
var url:String = encodeURI(fullPath);
urlRequest = new URLRequest( url+"downExcel?fullPath=" + fullPath);

修改tomcat的server.xml
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="utf-8"/>

设置完毕重启tomcat

 

你可能感兴趣的:(Flex,Flex,Flex)