论坛首页 编程语言技术论坛

java与flex结合做的登陆(连接数据库)

浏览 28811 次
精华帖 (0) :: 良好帖 (2) :: 新手帖 (1) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-03-21   最后修改:2009-04-27

在做项目的时候用的是php+flex,自己闲的没事用java+flex写的小例子,希望对java程序员学习flex有所帮助吧。java与flex结合有几种方式:

【1】:通过flex-plugin的一个插件吧它安装到你本机上。然后相应的把其plugin 和 features 文件 拷贝到 ecplise相应的目录下。结合 blazeds.war 放在tomcat 下 -- webapps下。

【2】:分别使用两个工具开发,完了,把class类放在flex下一个文件下。

 

 

 在这里我使用的数据库是mysql,需要自己建一个库:test  -- 表 login_user.

 

 

 抱歉由于压缩后超过了上传的大小,只能先贴出部分代码,如果各位需要的话,可以留下你们的邮箱。我发给你们,或者加我的qq:282215036.

 

----管理员分割线----

需要全部源代码,请给楼主发站内短信告知email地址,请不要直接跟贴。谢谢。

--------------

 

flex : 主页面

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:view="components.*"
 
 layout="absolute"
 width="100%"
    verticalScrollPolicy="off" xmlns:ns1="*"
    viewSourceURL="srcview/index.html"
    initialize="show()" >
   
    <mx:Script>
     <![CDATA[
       import mx.rpc.events.ResultEvent;
 import mx.controls.Alert;
    import mx.events.CloseEvent;
    import mx.managers.PopUpManager;
   
 /**
  * show()
  *
  * 初始状态 
  *
  * @param
  * @return void
  * @author Xip<xipei_1984@163.com>
  * @create 2009/03/17
  */    
     
    public function show():void
    {
       this.currentState="loginView";

    }
 /**
  * sendRequest()
  *
  * 发送请求,校验登陆 
  *
  * @param
  * @return void
  * @author Xip<xipei_1984@163.com>
  * @create 2009/03/17
  */      
    public function sendRequest():void
    {
     
       this.remoteObj.LoginDemo(this.username.text,this.passwd.text);
    }
 /**
  * LoginEnd()
  *
  * 返回方法 
  *
  * @param
  * @return void
  * @author Xip<xipei_1984@163.com>
  * @create 2009/03/17
  */      
    public function LoginEnd(event:ResultEvent):void
    {
        if(event.message.body){
           this.currentState="loginWindow";
        }
        else
        {
           this.currentState="loginView";
           this.username.text = "";
      this.passwd.text = "";
      this.username.setFocus();
        }
    }         
     ]]>
    </mx:Script>
   
 <mx:states>
  <mx:State name="loginWindow">
   <mx:AddChild>
    <view:loginWindow/>
   </mx:AddChild>
  </mx:State>
  <mx:State name="loginView">
   <mx:AddChild>
     <mx:Canvas label="登陆界面" width="100%" id="canvas" height="100%" color="#E3C227" themeColor="#89C9F2">
    <mx:Panel x="10" y="0" width="373" height="250" layout="absolute" id="loginCanvas">
     <mx:Label x="25" y="28" text="帐号:" width="60" fontSize="17"/>
     <mx:Label x="25" y="95" text="密码:" width="60" fontSize="17"/>
     <mx:TextInput x="74" y="28" id="username"  width="205"/>
     <mx:TextInput x="75" y="98" id="passwd" width="205" displayAsPassword="true"/>
     <mx:Button x="75" y="154" label="登陆" fontSize="15" click="sendRequest()" cornerRadius="8"/>
     <mx:Button x="222" fontSize="15" y="154" label="取消" cornerRadius="8"/>
    </mx:Panel>
  </mx:Canvas> 
   </mx:AddChild>
  </mx:State>
 </mx:states>
 <mx:RemoteObject id="remoteObj" destination="loginDemo"  endpoint="http://localhost:8089/hello/messagebroker/amf">
 <mx:method name="LoginDemo" result="LoginEnd(event)"/>
 </mx:RemoteObject>
</mx:Application>

 

remoting-config.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
    class="flex.messaging.services.RemotingService">
    <adapters>
        <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
    </adapters>
    <default-channels>
        <channel ref="my-amf"/>
    </default-channels>   
 <destination id="helloservice">
      <properties>    
        <source>com.jexchen.blazeds.HelloWorldService</source> 
      </properties>
   </destination>
   <destination  id="loginDemo">
      <properties>
       <source>com.jexchen.blazeds.VildateLogin</source>
      </properties>    
   </destination>
   <destination id="Hello">
     <properties>
       <source>com.jexchen.blazeds.HelloWorld</source>
     </properties>
   </destination>
</service>

 

java 代码:

 

package com.jexchen.blazeds;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.jexchen.utils.OpenDao;

public class VildateLogin {
 public boolean LoginDemo(String uname, String passwd) {
  boolean loginResult = false;
  OpenDao open = new OpenDao();
  if (null != uname && "" != passwd) {
   String sql = "select * from login_user where uname='" + uname
     + "' and passwd='" + passwd + "'";
   ResultSet rs = open.doQuery(sql);
   if (rs != null) {
    try {
     while (rs.next()) {
      loginResult = true;
     }
    } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return loginResult ;
    }
   }
  }
  return loginResult;
 }
}

   发表时间:2009-07-07  
发过去了!
0 请登录后投票
   发表时间:2009-07-08  
这样的话,那用户如果刷新一下页面,那就又回到登陆页面了。
0 请登录后投票
   发表时间:2009-07-15  
最近有个想法,把现在的这个系统的界面全部换成flex,框架用:struts2.0+hibernate3.0+spring2.5+Flex3.0。构思中……
0 请登录后投票
   发表时间:2009-07-17  
struts2.0+hibernate3.0+spring2.5+Flex3.0...
思路很清晰吧,flex远程调用后台程序.交互的问题就交给blazeds了.

0 请登录后投票
   发表时间:2009-07-17  
lichen0921 写道
struts2.0+hibernate3.0+spring2.5+Flex3.0...
思路很清晰吧,flex远程调用后台程序.交互的问题就交给blazeds了.


不过要把整个项目前台都换成flex需要不少功夫的.
0 请登录后投票
   发表时间:2009-07-17  
最近项目也不是很忙!就当是练手啦!
0 请登录后投票
   发表时间:2009-08-05  
建议使用PureMVC,这个不错!
0 请登录后投票
   发表时间:2009-08-19  
值得好好的研究!谢谢!
0 请登录后投票
   发表时间:2009-11-07  
这样的话,那HTML不是没什么作用了吗?

展示都给Flash了,那HTML干嘛?
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics