Flex4_HttpService组件
生活随笔
收集整理的這篇文章主要介紹了
Flex4_HttpService组件
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、在JavaWeb項(xiàng)目中新建Servlet(FlexLoginServelt) :
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html");response.setContentType("text/xml;charset=utf-8");PrintWriter out = response.getWriter();//接收Flex端傳來的參數(shù)String userName=request.getParameter("userName");String userPwd=request.getParameter("userPwd");String result="登錄失敗,用戶名或密碼錯(cuò)誤!";if("admin".equals(userName) || "".equals(userPwd)){result="登錄成功!";}//將登錄信息返回給客戶端 out.println(result);out.flush();out.close();}2、Flex端代碼
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"initialize="init()"><fx:Script><![CDATA[import mx.controls.Alert;import mx.rpc.events.FaultEvent;import mx.rpc.events.ResultEvent;private function init():void{btn_login.addEventListener(MouseEvent.CLICK,login);//加載HTTPService的返回監(jiān)聽 httpSer.addEventListener(ResultEvent.RESULT,httpSerResultHandler);httpSer.addEventListener(FaultEvent.FAULT,httpSerFaultHandler);}private function login(event:MouseEvent):void{httpSer.send();}//返回成功事件private function httpSerResultHandler(event:ResultEvent):void{Alert.show(event.result.toString(),"登錄提示");}//返回失敗事件private function httpSerFaultHandler(event:FaultEvent):void{Alert.show(event.fault.message as String,"登錄提示");}]]></fx:Script><fx:Declarations><s:HTTPService id="httpSer" url="http://localhost:8090/FlexHttpService/FlexLoginServelt" method="POST"><s:request><!--需要發(fā)送到服務(wù)器的參數(shù)名,及值,接收參數(shù)名時(shí)必須一致--><userName>{txt_userName.text}</userName><userPwd>{txt_userPwd.text}</userPwd></s:request></s:HTTPService></fx:Declarations><s:Panel x="37" y="40" width="250" height="200"><s:Label x="37" y="28" text="用戶名:"/><s:Label x="37" y="61" text="密 碼:"/><s:TextInput id="txt_userName" x="82" y="24"/><s:TextInput id="txt_userPwd" x="83" y="56" displayAsPassword="true"/><s:Button x="83" y="115" label="登錄" id="btn_login"/></s:Panel> </s:Application>3、效果圖:
轉(zhuǎn)載于:https://www.cnblogs.com/lovemoon714/archive/2012/05/25/2517684.html
總結(jié)
以上是生活随笔為你收集整理的Flex4_HttpService组件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Django 2.0.3安装-压缩包方式
- 下一篇: Swift中文件和图片上传处理