Morano88
Morano88

Reputation: 2077

Sending data from MXML file to JSP file (and recieving) using HTTPservice

I want to retrieve data from a Database and display inside a datagrid in a Flex web application. The way I'm thinking of doing it is :

  1. Send the Query data from .mxml file to the .jsp page using HTTPService.
  2. In the .jsp, connect to the database and retrieve the data using select statements.
  3. send the results back to the .mxml using HTTPService.

I know what to use but I have an ambiguity. In the (.mxml) I use xxx.send() to send the data. What do I use in the (.jsp) to send it back ?

Also, I know that I should store the results in an XML in the .jsp file, but how to do that ?

Upvotes: 0

Views: 710

Answers (1)

Nate
Nate

Reputation: 2881

You just output the XML data directly to the screen as you would with any other jsp web page. Pretend you're making a jsp to display some html, same concept applies, just display the XML instead.

  • yourpage.jsp :

    <% java.util.Date date = new java.util.Date(); %>
    <root><time><%= date %></time></root>
    

When you receive it, it will be stuffed into the result event based on the result format. For XML like you're talking, you'll want your service to look something like :

<mx:HTTPService id="myService" url="yourpage.jsp" method="GET" 
    resultFormat="e4x" result="myServiceResponse(event)" fault="httpFaultHandler(event)" showBusyCursor="true"/>

Then your response method looks something like this :

private function settingsResponse( e : ResultEvent) : void {
    myXML = e.result as XML;
    mx.controls.Alert.show('current server date/time is ' + String(myXML.time) );
    //   ...do whatever you want with your xml now!...
}

Upvotes: 1

Related Questions