Flex+struts2+json implementing a Flex and background HTTP service request

Source: Internet
Author: User
Tags rar

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
  1. <?xml version="1.0" encoding="Utf-8"?>
  2. <mx:application xmlns:mx="<a href="http://www.adobe.com/2006/mxml">   http://www.adobe.com/2006/mxml</a> "fontsize=" layout= "Absolute">
  3. <mx:Script>
  4. <! [cdata[
  5. Import Com.adobe.serialization.json.JSONDecoder;
  6. Import mx.rpc.events.FaultEvent;
  7. Import Mx.controls.Alert;
  8. Import mx.rpc.events.ResultEvent;
  9. Internal function Sendurl (): void{
  10. Set the Httpservice URL property to the action connection you want to access after Dd=new Date (). GetTime (); To eliminate browser caching
  11. 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 ();
  12. Call Httpservice's Send () method
  13. Hs.send ();
  14. Registering Success Events
  15. Hs.addeventlistener (resultevent.result,success);
  16. Registering failed Events
  17. Hs.addeventlistener (Faultevent.fault,faultresult);
  18. }
  19. function called by the failed event
  20. Internal function Faultresult (event:faultevent): void{
  21. Pop-up Failure message
  22. Alert.show (Event.fault.message);
  23. }
  24. Success function
  25. Internal function Success (event:resultevent): void{
  26. Converts the returned object to a string
  27. var userstr:string = event.result.toString ();
  28. Convert the string to a Jsondecoder object using the Class Jsondecoder () from the SWC package you just added
  29. var userjson:jsondecoder = new Jsondecoder (USERSTR);
  30. How to return to map
  31. var d:object = Userjson.getvalue (). Uerinfomap;
  32. var arryobject:array=[];
  33. For each (Var f:object in D) {
  34. Arryobject.push (f);
  35. //    }
  36. Userinfo.dataprovider = Arryobject;
  37. Returns how the list is handled
  38. Returning an object using the GetValue method of the Jsondecoder object
  39. Userinfo.dataprovider = Userjson.getvalue (). Userinfos;
  40. }
  41. ]]>
  42. </mx:Script>
  43. <!--Create Httpservice objects--
  44. <mx:httpservice id="HS" method="POST" showbusycursor="true"/>
  45. <!--Create a Send button and call the Sendurl () function--
  46. <mx:button id="requstdate" click="Sendurl ()" label= "send" x=" "y= " "/>"
  47. <!--Create a DataGrid control to bind the returned data-
  48. <mx:datagrid x=" y=" 131 "width=" 482 "height=" id= "UserInfo">
  49. <mx:columns>
  50. <mx:datagridcolumn headertext="user name" datafield="userName"/>
  51. <mx:datagridcolumn headertext="password" datafield="pwd"/>
  52. <mx:datagridcolumn headertext="email " datafield="email"/>
  53. <mx:datagridcolumn headertext="Age " datafield= "ages"/>
  54. </mx:columns>
  55. </mx:DataGrid>
  56. </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

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.