HTTPService 콤포넌트를 이용하여 웹서버에 요청할 때 파라미터를 전달하는 다양한 방법
MXML
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
private var employeeInfo:XMLList;
{
employeeInfo = event.result.emp as XMLList;
}
{
Alert.show(event.fault.faultString, "Error");
}
public function getDetailedInfo1():void {
var http:HTTPService = new HTTPService();
http.method="POST";
http.url = "http://localhost/flex/xmlEmpService4.jsp";
http.resultFormat = "e4x";
http.request.empno = txtEmpno.text;
http.addEventListener("result", handleXML);
http.addEventListener("fault", handleFault);
http.send();
}
public function getDetailedInfo2():void {
var params:Object = new Object();
params.empno = txtEmpno.text;
xmlRPC.send(params);
}
public function getDetailedInfo3():void {
xmlRPC.url="http://localhost/flex/xmlEmpService4.jsp?empno="+txtEmpno.text;
xmlRPC.send();
}
public function getDetailedInfo4():void {
var params:Object = new Object();
params["empno"] = txtEmpno.text;
xmlRPC.send(params);
}
public function getDetailedInfo5():void {
xmlRPC.request.empno = txtEmpno.text;
xmlRPC.send();
}
employeeInfo = null;
}
]]>
</mx:Script>
method="POST" url="http://localhost/flex/xmlEmpService4.jsp" useProxy="false">
<mx:request xmlns="">
<empno>{ txtEmpno.text }</empno>
</mx:request>
</mx:HTTPService>
<mx:Label x="49.5" y="39" text="HTTPService를 이용하여 파라미터를 전달하는 방법 테스트" fontSize="13" fontWeight="bold" textDecoration="underline"/>
<mx:Label x="43" y="85" text="사번(empno)입력" fontSize="12"/>
<mx:TextInput x="157" y="83" width="88" id="txtEmpno" text="7839"/>
<mx:DataGrid x="43" y="113" height="142" id="EmpList" dataProvider="{employeeInfo}" fontSize="12" textAlign="center">
<mx:columns>
<mx:DataGridColumn headerText="사 번" dataField="empno"/>
<mx:DataGridColumn headerText="이 름" dataField="ename"/>
</mx:columns>
</mx:DataGrid>
<mx:Button x="253" y="83" label="<empno>7839</empno>" click="xmlRPC.send();" width="187" height="22"/>
<mx:Button x="253" y="113" label="http.request.empno='7839'" width="187" id="btnDetail"
click="getDetailedInfo1();"/>
<mx:Button x="253" y="143" label="params.empno='7839'" width="187" id="btnDetail0"
click="getDetailedInfo2();"/>
<mx:Button x="253" y="173" label="emp.jsp?empno=7839" width="187" id="btnDetail1"
click="getDetailedInfo3();"/>
<mx:Button x="253" y="203" label="params['empno']='7839'" width="187" id="btnDetail2"
click="getDetailedInfo4();"/>
<mx:Button x="253" y="208" label="http.request.empno='7839'" width="187" id="btnDetail5"
click="getDetailedInfo5();"/>
<mx:Button x="253" y="233" label="Clear DataGrid" width="187" id="btnDetail3"
click="clearDataGrid();" fillAlphas="[1.0, 1.0]" fillColors="[#F8BA35, #F8BA35]"/>
</mx:Application>
테스트용 서버측 프로그램 (xmlEmpService04.jsp)
<%@ page contentType="text/xml;charset=utf-8" import="java.sql.*" %>
<%
Connection conn = null;
Statement stmt = null;
String jdbc_driver = "oracle.jdbc.OracleDriver";
String db_url = "jdbc:oracle:thin:@localhost:1521:ora9i";
String empno = request.getParameter("empno");
try{
Class.forName(jdbc_driver);
conn = DriverManager.getConnection(db_url,"scott","tiger");
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from emp where empno="+empno);
// EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
%>
<?xml version="1.0" encoding="utf-8"?>
<employee>
<%
while(rs.next()) { %>
<emp>
<empno><%=rs.getInt(1)%></empno>
<ename><%=rs.getString(2)%></ename>
<job><%=rs.getString(3)%></job>
<mgr><%=rs.getString(4)%></mgr>
<hiredate><%=rs.getString(5)%></hiredate>
<sal><%=rs.getInt(6)%></sal>
<comm><%=rs.getString(7)%></comm>
<deptno><%=rs.getInt(8)%></deptno>
</emp>
<% } %>
</employee>
<%
rs.close();
stmt.close();
conn.close();
}
catch(Exception e) {
out.println(e);
}
%>
'Flex' 카테고리의 다른 글
Flash Builder 4 Beta2에서 SVN 설치하기 (0) | 2010.10.18 |
---|---|
flex 다국어 (0) | 2010.10.01 |
Flex Encryption (MD5, SHA1, SHA224, SHA256, HMAC) (0) | 2010.10.01 |
FLEX로 화면캡쳐 및 이미지파일로 저장하기 (0) | 2010.08.13 |
flex (0) | 2010.06.21 |