刚学flex,做一个flex登录,点登录没反应
login.mxml文件
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:RemoteObject id="userLogin" destination="userDao"> <mx:method name="login" result="loginResult(event)"/> </mx:RemoteObject> <mx:Panel width="378" height="245" layout="absolute" horizontalCenter="-17" verticalCenter="2" title="用户登录" fontSize="12"> <mx:Label x="49" y="42" text="用户名:" fontSize="13"/> <mx:Label x="49" y="85" text="密 码:"/> <mx:TextInput x="107" y="39" height="25" id="uname"/> <mx:TextInput x="107" y="83" height="24" id="upass" displayAsPassword="true"/> <mx:Button x="107" y="136" label="登 录" click="sub()"/> <mx:Button x="202" y="136" label="重 置"/> </mx:Panel> <mx:Script> <![CDATA[ import mx.rpc.events.ResultEvent; import mx.controls.Alert; public var userId:int; public function sub():void{ if(uname.text==""||upass.text==""||uname.text==null||upass.text==null){ Alert.show("用户名和密码不能为空!"); }else{ userLogin.login(uname.text,upass.text); } } public function loginResult(evt:ResultEvent):void{ userId=evt.result as int; if(userId!=0){ Alert.show("登录成功"); }else{ Alert.show("登录失败"); } } ]]> </mx:Script></mx:Application>
<?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="userDao"> <properties> <source>com.jw.dao.UserDao</source> </properties> </destination></service>
public int login(String uname,String upass) throws Exception{ String sqlText="select * from t_user where uname='"+uname+"' and upass='"+upass+"'"; Connection c=getConnection(); Statement s=c.createStatement(); int count=0; ResultSet rs=s.executeQuery(sqlText); if(rs.next()){ count=1; } return count; }