Struts1.2+Jquery+Hibernate+Mysql实现登陆

来源:互联网 发布:广州文豆php怎么样 编辑:程序博客网 时间:2024/06/05 02:39

1,页面登陆代码:

页面登陆代码代码  收藏代码
  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
  2. <html>  
  3.     <head>  
  4.         <title>jquery登陆</title>  
  5.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  6.         <script type="text/javascript" src="js/jquery-1.4.2.js"></script>  
  7.         <script type="text/javascript">   
  8.             $(document).ready(function(){   
  9.                 // username 获取光标 $("#username").focus();   
  10.             });   
  11.             function checkForm(){  
  12.                  var name = $("#username").val();   
  13.                  if(name.length<=0){   
  14.                     $("#msgName").html("the username is null!");  
  15.                      return false;    
  16.                  }else{   
  17.                     $("#msgName").html("");  
  18.                  }   
  19.                  var pass = $(".password").val();   
  20.                  if(pass.length<=0){   
  21.                     $("#msgPass").html("the password is null!");   
  22.                     return false;   
  23.                  }else{   
  24.                     $("#msgPass").html("");   
  25.                  }   
  26.                    
  27.                  // 提交到后台进行验证   
  28.                  $.ajax({ type: "POST",// 指定是post还是get,当然此处要提交,当然就要用post了   
  29.                           cache: "false",//默认: true,dataType为script时默认为false) jQuery 1.2 新功能,设置为 false 将不会从浏览器缓存中加载请求信息。   
  30.                           url: "login.do?method=login",//发送请求的地址。   
  31.                           data: "username=" + name + "&password=" + pass ,//发送到服务器的数据   
  32.                           dataType: "text",//返回纯文本字符串 timeout:20000,// 设置请求超时时间(毫秒)。   
  33.                           error: function () {//请求失败时调用函数。  
  34.                            $("#msg").html("请求失败!"); }, success://请求成功后回调函数。  
  35.                             function(message) {  
  36.                                  $("#msg").html(message);  
  37.                             }  
  38.                            }); return false;   
  39.                  }  
  40.          </script>  
  41.     </head>  
  42.     <body>  
  43.         <form action="" method="post" onSubmit="return checkForm()">  
  44.             <table width="388" border="0" cellpadding="0" cellspacing="0">  
  45.                 <tr>  
  46.                     <td colspan="2">  
  47.                         <span id="msg" style="color: red"></span>  
  48.                     </td>  
  49.                 </tr>  
  50.                 <tr>  
  51.                     <td width="92">  
  52.                         用户名:  
  53.                     </td>  
  54.                     <td width="280">  
  55.                         <input type="text" name="username" id="username">  
  56.                         <span id="msgName" style="color: red"></span>  
  57.                     </td>  
  58.                 </tr>  
  59.                 <tr>  
  60.                     <td>  
  61.                         密码:  
  62.                     </td>  
  63.                     <td>  
  64.                         <input type="password" name="password" id="password"  
  65.                             class="password">  
  66.                         <span id="msgPass" style="color: red"></span>  
  67.                     </td>  
  68.                 </tr>  
  69.                 <tr>  
  70.                     <td colspan="2">  
  71.                         <input type="submit" name="button" value="submit">  
  72.                     </td>  
  73.                 </tr>  
  74.             </table>  
  75.         </form>  
  76.     </body>  
  77. </html>  
原创粉丝点击