Flex HTTPService 给后台传递参数

采用URLVariables对象

<? xml version="1.0" encoding="utf-8" ?>
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
     layout
="absolute"  fontSize ="12"
    
>
    
< mx:Script >
        
<![CDATA[
            import mx.controls.Alert;
            import mx.rpc.events.ResultEvent;
            //对提交给后台的参数进行UTF-8的编码处理
            private function httpEncoding(param:String):String{
                return encodeURIComponent(param);
            }
            private function httpEncoding0(param:String):String{
                return param;//encodeURI(param);
            }
            private function doRequest():void{
                btn_do.enabled=false;
                var url:String = "http://localhost:8600/grid.jsp";
                //以下那样写后台会乱码,不管是否做URI编码转换
                //url += "?user="+httpEncoding0("用户名");
                //url += "&psw="+httpEncoding0("密码");
                //trace(url);
                srv.url = url;
                //srv.send();
                //以下这样写正常
                var params:URLVariables = new URLVariables();
                //这个user,psw就是传入后台的参数user,jsp就用 request.getParameter("user")来取
                params.user = httpEncoding("用户名");
                params.psw = httpEncoding("密码");
                srv.send(params);            
            }
            private function resultHandler(event:ResultEvent):void{
                Alert.show("与后台交互结束,前台开始取得的数据...","提示信息");
                btn_do.enabled=true;
            }
        
]]>
    
</ mx:Script >
    
< mx:HTTPService  id ="srv"  result ="resultHandler(event);" />
    
< mx:Panel  title ="测试与jsp后台交互"  layout ="absolute"  width ="100%"  height ="90%" >
        
< mx:Button  id ="btn_do"  label ="取得数据"  click ="doRequest();" />
        
< mx:Spacer  height ="1" />
        
< mx:DataGrid  dataProvider ="{srv.lastResult.catalog.product}"  width ="100%"  height ="100%"  y ="28" />      
    
</ mx:Panel >
</ mx:Application >

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