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/halo" minWidth="1024" minHeight="768">
- <fx:Script>
- <!--[CDATA[
- import mx.controls.*;
- import mx.rpc.events.ResultEvent;
- import mx.rpc.http.mxml.HTTPService;
- protected function button1_clickHandler(event:MouseEvent):void
- {
- var addNew:HTTPService = new HTTPService();
- addNew.resultFormat = "text" ;
- addNew.method = "POST";
- addNew.url = "http://localhost:8084/Flex_web/flex";
- addNew.addEventListener(ResultEvent.RESULT,result_Handler);
- var param:Object = new Object();
- param.user = user.text;
- param.pwd = pwd.text;
- addNew.send(param);
- }
- public function result_Handler(event:ResultEvent):void
- {
- var mes:String = event.message.body.toString();
- Alert.show("成功!" + mes,"信息");
- }
- ]]-->
- </fx:Script>
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <s:Panel x="200" y="110" width="224" height="157" title="登录系统">
- <s:Button x="24" y="92" label="登录" click="button1_clickHandler(event)" width="171" focusEnabled="true"/>
- <s:TextInput x="67" y="10" id="user"/>
- <s:TextInput x="67" y="49" id="pwd"/>
- <s:Label x="20" y="15" text="用户名:"/>
- <s:Label x="20" y="55" text="密码:"/>
- </s:Panel>
- </s:Application>
<?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/halo" minWidth="1024" minHeight="768"> <fx:Script> <!--[CDATA[ import mx.controls.*; import mx.rpc.events.ResultEvent; import mx.rpc.http.mxml.HTTPService; protected function button1_clickHandler(event:MouseEvent):void { var addNew:HTTPService = new HTTPService(); addNew.resultFormat = "text" ; addNew.method = "POST"; addNew.url = "http://localhost:8084/Flex_web/flex"; addNew.addEventListener(ResultEvent.RESULT,result_Handler); var param:Object = new Object(); param.user = user.text; param.pwd = pwd.text; addNew.send(param); } public function result_Handler(event:ResultEvent):void { var mes:String = event.message.body.toString(); Alert.show("成功!" + mes,"信息"); } ]]--> </fx:Script> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <s:Panel x="200" y="110" width="224" height="157" title="登录系统"> <s:Button x="24" y="92" label="登录" click="button1_clickHandler(event)" width="171" focusEnabled="true"/> <s:TextInput x="67" y="10" id="user"/> <s:TextInput x="67" y="49" id="pwd"/> <s:Label x="20" y="15" text="用户名:"/> <s:Label x="20" y="55" text="密码:"/> </s:Panel> </s:Application>
servlet代码:
- package advang;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class flexServlet extends HttpServlet {
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- String user = request.getParameter("user");
- String pwd = request.getParameter("pwd");
- user = new String(user.getBytes("ISO8859-1"),"UTF-8");
- pwd = new String(pwd.getBytes("ISO8859-1"),"UTF-8");
- PrintWriter out = response.getWriter();
- try {
- out.print("从服务器返回的数据[" + user + "][" + pwd + "]!");
- } finally {
- out.close();
- }
- }
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- @Override
- public String getServletInfo() {
- return "Short description";
- }
- }