免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
jFinal寫(xiě)的登錄功能的具體實(shí)現(xiàn)

不細(xì)講,主要留自己下次復(fù)制用的(嘿嘿)

  1. <span style="font-size:18px;">  //登錄   model  
  2.         public boolean findUserLogin(String username,String password,List<User> userlist){  
  3.             String querysql="select * from user where username=? and password=? AND state=1 ";  
  4.             List<User> list;  
  5.             try{  
  6.                 //綁定參數(shù)查詢數(shù)據(jù)使用find()方法查詢數(shù)據(jù)返回?cái)?shù)據(jù)為集合  
  7.                 list=this.dao.find(querysql, username,password);  
  8.             }catch(Exception ex){  
  9.                 ex.printStackTrace();  
  10.                 return false;  
  11.             }  
  12.             if(list.isEmpty() || list==null){  
  13.                 return false;  
  14.             }  
  15.             //將登錄者數(shù)據(jù)添加到userlist集合中  
  16.             userlist.add(list.get(0));  
  17.             return true;  
  18.               
  19.         }</span>  

  1. <span style="font-size:18px;">//登錄 Controller  
  2.     public void login(){  
  3.         //獲取登錄者信息查詢  
  4.         String username=getPara("username");  
  5.           
  6.         String password=getPara("password");  
  7.           
  8.         List<User> userlist=new ArrayList<User>();  
  9.         boolean bflag = User.dao.findUserLogin(username, password, userlist);  
  10.         //如果數(shù)據(jù)能查出來(lái)保持會(huì)話更新登陸時(shí)間并將登錄者信息響應(yīng)回去  
  11.         if(bflag){  
  12.             //this.getSession().setAttribute("username", username);  
  13.             //創(chuàng)建當(dāng)前時(shí)間以字符串形式返回  
  14.             String t=TimeHelper.Format("yyyy-MM-dd HH:mm:ss");  
  15.             //記錄登錄者登錄信息  
  16.             String sql="update user set LoginTime=? where username=?";  
  17.             //使用update方法執(zhí)行修改語(yǔ)句  
  18.             Db.update(sql, t,username);  
  19.             //設(shè)置代表登錄狀態(tài)的信息  
  20.             setAttr("status",0);  
  21.             //儲(chǔ)存登錄者信息于請(qǐng)求中  
  22.             setAttr("user",userlist.get(0));  
  23.             //將登錄者信息保存到會(huì)話session中  
  24.             this.setSessionAttr("adminlogin", userlist.get(0));  
  25.               
  26.         }else{  
  27.             //如果失敗登錄狀態(tài)為-1代表  
  28.             setAttr("status",-1);  
  29.         }  
  30.         //響應(yīng)請(qǐng)求  
  31.         this.renderJson();  
  32.           
  33.     }</span>  

  1. <span style="font-size:18px;"><-- 局部的html,jsp頁(yè)面 -->           </span>  
  1. <span style="font-size:18px;"> <form method="post">  
  2.                 <div class="form-group">  
  3.                     <input type="text" class="form-control" placeholder="用戶名" required="required" id="username">  
  4.                 </div>  
  5.                 <div class="form-group">  
  6.                     <input type="password" class="form-control" placeholder="密碼" required="required" id="password">  
  7.                 </div>  
  8.                 <button id="login" type="button" class="btn btn-primary block full-width m-b" onclick="javascript:loginSubmit()">登 錄</button>  
  9.                                                                                     
  10.                 <!--    
  11.                 <p class="text-muted text-center"> <a href="login.html#"><small>忘記密碼了?</small></a> | <a href="register.html">注冊(cè)一個(gè)新賬號(hào)</a>  
  12.                 </p>  
  13.                 -->  
  14.   
  15.             </form></span>  

敲擊回車(chē)鍵觸發(fā) 登錄的單擊事件

  1. <span style="font-size:18px;"> <script>  
  2.     $("body").keydown(function() {  
  3.         if (event.keyCode == "13") {//keyCode=13是回車(chē)鍵  
  4.             $("#login").click();  
  5.         }  
  6.     });  
  7.       
  8.     </script></span>  

ajax代碼如下:

  1. <span style="font-size:18px;">/* 
  2.  *管理員登錄  
  3.  */  
  4. function loginSubmit(){  
  5.     //獲取login.jsp頁(yè)面的數(shù)據(jù)登錄者姓名和密碼  
  6.     var username=$("input#username").val();  
  7.     var password=$("input#password").val();  
  8.     if(username==""){  
  9.         layer.tips('用戶名不能為空',"#username",{  
  10.             tips:[2,'#ff0000']});  
  11.         $("input#username").focus();  
  12.         return;  
  13.     }  
  14.     if(password==""){  
  15.         layer.tips('密碼不能為空','#password',{  
  16.             tips:[2,'#ff0000']  
  17.         });  
  18.         $("input#password").focus();      
  19.         return;  
  20.     }  
  21.     //當(dāng)密碼和用戶名不為空的時(shí)候使用Ajax進(jìn)行用戶信息登錄驗(yàn)證  
  22.     var strJSON ={"username":username,"password":password};  
  23.     jQuery.ajax({  
  24.         url:"./user/login",  
  25.         type:"POST",  
  26.         data:strJSON,  
  27.         success:function(obj){  
  28.             if(obj.status==0){  
  29.                 //將登錄者信息保存在cookie中以便添加信息時(shí)添加經(jīng)濟(jì)人  
  30.                 setCookie("loginname",obj.user.username);  
  31.                 //跳轉(zhuǎn)到首頁(yè)  
  32.                 window.location.replace("index.jsp");//登錄成功  
  33.             }else{  
  34.                 layer.alert('用戶名或密碼不正確', {  
  35.                   skin: 'layui-layer-molv' //樣式類名  
  36.                   ,closeBtn: 0  
  37.                   ,shift: 4 //動(dòng)畫(huà)類型  
  38.                 });  
  39.             }  
  40.         },  
  41.         error:function(){  
  42.             layer.alert('系統(tǒng)錯(cuò)誤',{skin:'layui-layer-molv'  
  43.                 ,closeBatn:0});  
  44.         },  
  45.         complete:function(obj){  
  46.             if(obj.status==200);  
  47.         }  
  48.     });  
  49. }</span>  



本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
成功vue登錄及token驗(yàn)證
Android的intent之間復(fù)雜參數(shù)的傳遞
用Python登錄賬戶
List.Contains實(shí)現(xiàn)對(duì)比
一個(gè)jquery-ajax post例子ajax 登陸
表單頁(yè)面
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服