반응형
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Panel width="350" height="250" layout="absolute" horizontalCenter="0" verticalCenter="0">
<mx:DataGrid horizontalCenter="0" verticalCenter="-20" dataProvider="{emplist}">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="ename"/>
<mx:DataGridColumn headerText="Phone" dataField="phone"/>
<mx:DataGridColumn headerText="Email" dataField="email"/>
</mx:columns>
</mx:DataGrid>
<mx:Button label="click me" horizontalCenter="0" verticalCenter="84" click="httpRequest.send()"/>
</mx:Panel>
<mx:HTTPService id="httpRequest" method="post" result="result(event)" fault="fault(event)" resultFormat="e4x" url="http://192.168.0.139/Webtest/flex/emp.jsp"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable]public var emplist:XMLList;
public function result(event:ResultEvent):void{
emplist = XMLList(event.result.emp);
}
public function fault(event:FaultEvent):void{
mx.controls.Alert.show("fail");
}
]]>
</mx:Script>
</mx:Application>
<%@ page contentType="text/html; charset=UTF8"%>
<employees>
<emp>
<ename>scott</ename>
<phone>22-333-3453</phone>
<email>scott@flex.com</email>
</emp>
<emp>
<ename>allen</ename>
<phone>24-233-3456</phone>
<email>allen@flex.com</email>
</emp>
<emp>
<ename>smith</ename>
<phone>23-323-5675</phone>
<email>smith@flex.com</email>
</emp>
<emp>
<ename>ford</ename>
<phone>25-323-3366</phone>
<email>ford@flex.com</email>
</emp>
<emp>
<ename>john</ename>
<phone>27-333-5686</phone>
<email>john@flex.com</email>
</emp>
<emp>
<ename>ward</ename>
<phone>27-243-2356</phone>
<email>ward@flex.com</email>
</emp>
</employees>
반응형