There are a couple of different ways. To start, you can use a servlet
that generates XML and use an HTTPService in Flex. A more
sophisticated option is to use the free BlazeDS data service tool to
pass objects between Java and Flex.
For the first option, you can create an HTTPService like this,
import mx.rpc.http.HTTPService;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
private function getServletXML():void {
var service:HTTPService = new HTTPService();
service.cancel(); // good idea to cancel service first.
service.url = "http://myserver.com/MyXMLServlet";
service.resultFormat = "e4x"; // Makes XML nodes accessible in
ActionScript
service.contentType = "application/xml";
service.addEventListener(ResultEvent.RESULT, serviceResultHandler);
service.addEventListener(FaultEvent.FAULT, serviceFaultHandler);
service.send();
}
private function serviceResultHandler(event:ResultEvent):void {
var myXML:XML = XML(event.result);
// here you'd do something with the myXML object, such as bind it to
a datagrid
}
private function serviceFaultHandler(event:FaultEvent):void {
Alert.show(event.fault.message,"Could not read XML servlet.");
}
You can look at this page for an example of connecting a servlet to
Flex:
http://blog.kevinhoyt.org/2007/12/07/flex-to-java-servlet-file-upload/
Another example: http://learn.adobe.com/wiki/display/Flex/2b.+Code+Files
To produce efficient XML in Java, look up the examples on this page,
http://www.javazoom.net/services/newsletter/xmlgeneration.html
-Alex
--- In [email protected], "saritha" <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> How to communicate between Flex and Java?
>