Skip navigation
Currently Being Moderated

How to retrieve data sent by Flash 4 HttpService, in the server side (Servlet)

Nov 29, 2011 4:00 AM

Tags: #flash #parameters #servlet

I'm using Flash 4.0 as UI tier, and I'm trying to send data to the server side, which runs on Tomcat. I wrote a servlet that the calls are directed to it. But I do not understand how can I see the data that was sent from the flash tier. to clarify, hereby example:

Flash tier:

<fx:Declarations>
   
<s:HTTPService
       
id="setCustomerDataService"
       
url="http://localhost:8080/AnalyticsPortalWebUI-1.0/setCustomerData"
       
useProxy="false" method="POST" resultFormat="text"
       
result="onSetCustomerDataResult(event)"
       
fault="fault(event)">
   
</s:HTTPService>

</fx:Declarations>

<fx:Script>
    <![CDATA[

        private function onSubmitCustomerDataClick(event:MouseEvent):void
        {
            var item:UsageInfoItem = new UsageInfoItem();
                        ....
            //i use JSON to encode,but it's not related to my question
                            var data:String = JSON.encode(item);
            //query:
            setCustomerDataService.send(data);
        }


    ]]>
</fx:Script>

my Servlet:

public void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
{
  
//how can I retrieve "data" from flash here?
}

so my question - how can I retrieve "data" from Flash, in my Servlet?

Do I sent the data correctly to the server, or do I have a mistake here? What am I missing?

thanks, Ohad

 
Replies
  • Currently Being Moderated
    Nov 29, 2011 5:13 AM   in reply to ohadr.com

    this is how you do it:

    in the flash side:

            private function onSubmitCustomerDataClick(event:MouseEvent):void
           
    {
               
    var item:UsageInfoItem = new UsageInfoItem();
                               
    ....
               
    **//this is how you do it:**
               
    var params:Object = {};

               
    var data:String = JSON.encode(item);
               
    params["paramName"] = data;
               
    //query:
                setCustomerDataService
    .send(params);
           
    }

    in the server end:

    public void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
    {
      
    String customerDataJsoned = httpRequest.getParameter("paramName");

      
    if(customerDataJsoned != null)
      
    {
          
    ObjectMapper mapper = new ObjectMapper();
          
    CustomerData customerData = mapper.readValue(customerDataJsoned, CustomerData.class);
          
    String customerId = customerData.getCustomerId();
      
    }
    }
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points