Flex - Http Post 인자값(Params) 포함하여 호출

Programming/Flex 2007.08.10 16:59 Posted by 파란크리스마스

출처

http://livedocs.adobe.com/flex/1/asdocs/mx/servicetags/HTTPService.html

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
 creationComplete="init()">
 
 <mx:Script>
  <![CDATA[
   import mx.collections.*;
   import mx.rpc.http.HTTPService;
   import mx.controls.dataGridClasses.DataGridColumn;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   
   public var httpData:HTTPService;   

   [Bindable]
   public var xlcData:XMLListCollection;
   
   public function init():void
   {
    var params:Object = new Object();
    params.keyname = "freeboard";
    params.qryname = "list";

    httpData = new HTTPService();
    httpData.url = "http://localhost:8080/examples/xmldata.jsp";
    httpData.method = "POST";
    httpData.resultFormat="e4x";
    httpData.addEventListener("result", resultHandler);
    httpData.addEventListener("fault", faultHandler);
    httpData.send(params);   
   }  
   
   public function resultHandler(e:ResultEvent):void
   {
    var xlData:XMLList = new XMLList(e.result);    
//    mx.controls.Alert.show(xlData.data.row.toXMLString());
    grid1.dataProvider = xlData.data.row;
   }  
   
   public function faultHandler(e:FaultEvent):void
   {
    mx.controls.Alert.show("데이타를 읽는 중 에러\n"+e.fault.faultString);
   }
   ]]>
  </mx:Script>  

 <mx:DataGrid id="grid1" x="233" y="177" width="457">
  <mx:columns>
   <mx:DataGridColumn headerText="Column 1" dataField="c1"/> 
   <mx:DataGridColumn headerText="Column 2" dataField="c2"/>
  </mx:columns>
 </mx:DataGrid>
 
</mx:Application>


xmldata.jsp

<?xml version="1.0" encoding="iso-8859-1"?>
<%@ page language="java" contentType="text/xml" %>
<%@ page import="meta.*"%>
<%
String keyname= request.getParameter("keyname");
String qryname= request.getParameter("qryname");

System.out.println(keyname + "/" + qryname);

String xmldata = MetaBoard.getInstance().getQueryRun(keyname, qryname);
%>
<root>
<%=xmldata%>
</root>


신고


 

티스토리 툴바