Http://www.fengfly.com/plus/view-191093-1.html
Flex+struts2+json Backstage code I don't say much here. Do not know please read my previous article "Struts2+jquery+json implementation of asynchronous interaction," the article, there is no change in the background.
This focuses on the flex-side implementation code.
The first step:
Download the As3corelib-.92.1.zip file from the http://code.google.com/p/as3corelib/ website and unzip it in as3corelib-.92.1\ There is a AS3CORELIB.SWC file in the As3corelib-.92.1\lib directory that copies the file to the Libs directory of your Flex project. will be able to work. Take a look at the Flex code:
Flex Code Code
- <?xml version="1.0" encoding="Utf-8"?>
- <mx:application xmlns:mx="<a href="http://www.adobe.com/2006/mxml"> http://www.adobe.com/2006/mxml</a> "fontsize=" layout= "Absolute">
- <mx:Script>
- <! [cdata[
- Import Com.adobe.serialization.json.JSONDecoder;
- Import mx.rpc.events.FaultEvent;
- Import Mx.controls.Alert;
- Import mx.rpc.events.ResultEvent;
- Internal function Sendurl (): void{
- Set the Httpservice URL property to the action connection you want to access after Dd=new Date (). GetTime (); To eliminate browser caching
- Hs.url = "<a href="http://localhost:8080/fsj/flexstrutsjson!hdlist.action?dd=% +new">http://localhost:8080/fsj/flexstrutsjson!hdlist.action?dd="+new</a> Date (). GetTime ();
- Call Httpservice's Send () method
- Hs.send ();
- Registering Success Events
- Hs.addeventlistener (resultevent.result,success);
- Registering failed Events
- Hs.addeventlistener (Faultevent.fault,faultresult);
- }
- function called by the failed event
- Internal function Faultresult (event:faultevent): void{
- Pop-up Failure message
- Alert.show (Event.fault.message);
- }
- Success function
- Internal function Success (event:resultevent): void{
- Converts the returned object to a string
- var userstr:string = event.result.toString ();
- Convert the string to a Jsondecoder object using the Class Jsondecoder () from the SWC package you just added
- var userjson:jsondecoder = new Jsondecoder (USERSTR);
- How to return to map
- var d:object = Userjson.getvalue (). Uerinfomap;
- var arryobject:array=[];
- For each (Var f:object in D) {
- Arryobject.push (f);
- // }
- Userinfo.dataprovider = Arryobject;
- Returns how the list is handled
- Returning an object using the GetValue method of the Jsondecoder object
- Userinfo.dataprovider = Userjson.getvalue (). Userinfos;
- }
- ]]>
- </mx:Script>
- <!--Create Httpservice objects--
- <mx:httpservice id="HS" method="POST" showbusycursor="true"/>
- <!--Create a Send button and call the Sendurl () function--
- <mx:button id="requstdate" click="Sendurl ()" label= "send" x=" "y= " "/>"
- <!--Create a DataGrid control to bind the returned data-
- <mx:datagrid x=" y=" 131 "width=" 482 "height=" id= "UserInfo">
- <mx:columns>
- <mx:datagridcolumn headertext="user name" datafield="userName"/>
- <mx:datagridcolumn headertext="password" datafield="pwd"/>
- <mx:datagridcolumn headertext="email " datafield="email"/>
- <mx:datagridcolumn headertext="Age " datafield= "ages"/>
- </mx:columns>
- </mx:DataGrid>
- </mx:Application>
It is important to note that the method executes more slowly in the case of a large amount of data in JSON.
Related article:Http://www.infoq.com/cn/articles/flex-xml-json
- as3corelib-.92.1.zip (655 KB)
- Flex-side code. RAR (820.9 KB)
- server-side Java code. RAR (3.7 MB)
Flex+struts2+json implementing a Flex and background HTTP service request