How Does Flex httpservice PASS Parameters (zt) to the backend)

Source: Internet
Author: User

ZT from: http://www.blogjava.net/yczz/articles/144363.html

 

I have read some documents recently and summarized some <mx: httpservice> methods for passing parameters to the background, as shown below:

Method 1: Use the urlvariables object

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" <br/> layout = "absolute" fontsize = "12" <br/> <mx: SCRIPT> <br/> <! -- [CDATA [<br/> Import MX. controls. alert; <br/> Import MX. RPC. events. resultevent; <br/> // encode the parameters submitted to the backend. <br/> private function httpencoding (Param: string ): string {<br/> return encodeuricomponent (PARAM); <br/>}< br/> private function httpencoding0 (Param: string): String {<br/> return Param; // encodeuri (PARAM); <br/>}< br/> private function dorequest (): void {<br/> btn_do.enabled = false; <br/> va R URL: String = "http: // localhost: 8600/grid. JSP "; <br/> // The background will be garbled in the way below, no matter whether URI encoding is converted or not <br/> // URL + = "? User = "+ httpencoding0 (" username "); <br/> // URL + =" & psw = "+ httpencoding0 (" password "); <br/> // trace (URL); <br/> srv. url = URL; <br/> // srv. send (); <br/> // write normally as follows <br/> var Params: urlvariables = new urlvariables (); <br/> // the user, psw is the parameter user passed in to the background, and JSP uses request. getparameter ("user") to get <br/> Params. user = httpencoding ("username"); <br/> Params. psw = httpencoding ("password"); <br/> srv. send (Params); <br/>}< br/> private function resulthandler (Event: resultevent): void {<br/> alert. show ("the interaction with the background ends, and the foreground begins to obtain the data... "," prompt message "); <br/> btn_do.enabled = true; <br/>}< br/>] --> <br/> </MX: SCRIPT> <br/> <mx: httpservice id = "SRV" result = "resulthandler (event);"/> <br/> <mx: panel Title = "test and JSP background interaction" layout = "absolute" width = "100%" Height = "90%"> <br/> <mx: button id = "btn_do" label = "Get Data" Click = "dorequest ();"/> <br/> <mx: spacer Height = "1"/> <br/> <mx: DataGrid dataprovider = "{srv. lastresult. catalog. product} "width =" 100% "Height =" 100% "Y =" 28 "/> <br/> </MX: Panel> <br/> </MX: Application>Method 2: Use <mx: Request/> and demonstrate the usage of MX: State. [from the Internet]:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute"> <br/> <mx: States> <br/> <mx: state name = "logged in"> <br/> <mx: setproperty target = "{Panel1}" name = "width" value = "95%"/> <br/> <mx: setproperty target = "{Panel1}" name = "height" value = "95%"/> <br/> <mx: removechild target = "{password}"/> <br/> <mx: removechild target = "{username}"/> <br/> <mx: removechild target = "{label1}"/> <B R/> <mx: removechild target = "{submit}"/> <br/> <mx: removechild target = "{label2}"/> <br/> <mx: setproperty target = "{Panel1}" name = "title" value = "members section"/> <br/> <mx: addchild relativeto = "{Panel1}" position = "lastchild"> <br/> <mx: label x = "10" Y = "10" text = "welcome to the members section! "/> <Br/> </MX: addchild> <br/> <mx: addchild relativeto = "{Panel1}" position = "lastchild"> <br/> <mx: label x = "10" Y = "36" text = "here you can do great things, like join the forums @ Viper creations! "/> <Br/> </MX: addchild> <br/> <mx: addchild relativeto = "{Panel1}" position = "lastchild"> <br/> <mx: label x = "10" Y = "62" text = "label"/> <br/> </MX: addchild> <br/> </MX: state> <br/> </MX: States> <br/> <mx: SCRIPT> <br/> <! -- [CDATA [<br/> Import MX. RPC. events. resultevent; </P> <p>]> <br/> </MX: SCRIPT> <br/> <mx: SCRIPT> </P> <p> <! [CDATA [<br/> private function checklogin (EVT: resultevent): void <br/>{< br/> If (EVT. result. loginsuccess = "yes") <br/>{< br/> currentstate = "logged in"; <br/>}< br/> If (EVT. result. loginsuccess = "no") <br/>{</P> <p> MX. controls. alert. show ('invalidusername/password'); <br/>}< br/>] --> <br/> </MX: SCRIPT> <br/> <mx: httpservice id = "login_user" result = "checklogin (Event) "showbusycursor =" true "method =" Post "url =" http://www.vipercreations.com/site_admin/login.php "useproxy =" false "> <br/> <mx: request xmlns = ""> <br/> <username> <br/> {username. text} <br/> </username> <br/> <password> <br/> {password. text} <br/> </password> <br/> </MX: Request> <br/> </MX: httpservice> </P> <p> <mx: panel resizeeffect = "resize" width = "250" Height = "200" layout = "absolute" Title = "Login System" horizontalcenter = "0" verticalcenter = "-2" id = ""Panel1"> <br/> <mx: label x = "10" Y = "10" text = "username:" id = "label1"/> <br/> <mx: textinput x = "10" Y = "36" id = "username"/> <br/> <mx: label x = "10" Y = "66" text = "Password:" id = "label2"/> <br/> <mx: textinput x = "10" Y = "92" id = "password" displayaspassword = "true"/> <br/> <mx: button x = "10" Y = "122" label = "Submit" id = "Submit" Click = "login_user.send ();"/> <br/> </MX: panel> </P> <p> </MX: Application> 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.