zoukankan      html  css  js  c++  java
  • 使用spring+ibatis+jquerymobile做的一个简单的用户登录

    sql代码:<select id="getVaildateUser" resultClass="AppUser" parameterClass="AppUser">
           SELECT
            * from omcm_user
          WHERE UserName=#username#
          <dynamic>
           <isNotEmpty property="password">AND Password =#password# </isNotEmpty>    
          </dynamic>
        </select>

    dao层:public boolean loginform(AppUser user);

    daoImpl层:

    public boolean loginform(AppUser user) {
      try {
       AppUser users = (AppUser) getSqlMapClientTemplate().queryForObject("getVaildateUser",user);
       return users==null?false:true;
      } catch (DataAccessException e) {
       e.printStackTrace();
      }return false;
     }

    server层: public boolean loginform(AppUser user);

    serverImpl层:

    public boolean loginform(AppUser user) {
      return systemDao.loginform(user);
     }

    control层:

    public void loginIndex(HttpServletRequest request,
       HttpServletResponse response, AppUser user) {
      Map<String, Boolean> map=new HashMap<String, Boolean>();
      boolean resu=systemService.loginform(user);
      map.put("msg", resu);
      Util.writeUtf8Text(response, JsonUtil.objectjson(map));
     }

    页面代码:

    <script type="text/javascript">
     $(document).ready(function() { 
            $("input[id]").bind("focus",function () {  
             if($(this).attr("id")=='username'||$(this).attr("id")=='password') 
              $(this).attr("value","");  
              });  
              $("#submit").bind("click", function() { 
                   if (valid()) {
                    $.ajax({ 
                     type: "POST", 
                      url: "http://localhost:8080/OmcmWap/system.do?event=loginIndex", 
                      data: $("#loginform").serialize(),
                      success : function(data) {
              if (data=='{"msg":true}') {
               alert("登录成功!");
                $.mobile.changePage("content/first.html","slidedown", true, true);
              } else {
               alert("登录失败!");
                  $.mobile.changePage("content/loginfail.html","slidedown", true, true); 
              }
             },
             error : function(data) {
              alert("出错了,请联系管理员!");
             }
                      });  
                    } 
                 }) 
              }); 
             function valid(){ 
                if($("#username").attr("value")==''||$("#password").attr("value")=='') 
                { 
                    $.mobile.changePage("content/loginfail.html","slidedown", true, true); 
                    return false;            
                } 
                return true; 
           }; 
    </script>
    <style type="text/css">
     p {
      font-size: 1.5em;
      font-weight: bold;
     }
     #submit{
      float:right; margin:10px;
     }
     #toregister{
      float:right; margin:10px;
     }
     #toregist{
      float:left; margin:10px;
     }
     </style>

    </head>
    <body>
    <section id="page1" data-role="page">
      <header data-role="header" data-theme="b">
      <h1>用户登录</h1>
      </header>
      <div data-role="content" class="content">
      <form method="post" id="loginform">
      <input type="text" id="username" name="username" value="用户名"/><br>
      <input type="password" name="password" id="password" value="密码输入提示"/>
      <a href="#" data-role="button" id="toregister">注册</a>
      <a href="#" data-role="button" id="submit" data-theme="b">登录</a>
      </form>
      </div>
      <footer data-role="footer"><h1>
      版权所有中国移动
      </h1></footer>
    </section>
    </body>

  • 相关阅读:
    JSP的组成
    什么是JSP
    JSP和Servlet分工图
    Linux逻辑卷管理LVM2详解
    ESXi主机和NTP server快速进行时间同步
    VMwareCLI命令参考
    使用Logminer工具分析DML和DDL操作
    TKPROF使用
    iSCSI存储设备的udev绑定 以及iscsi重启卡住解决方法
    Oracle 10g EM证书问题
  • 原文地址:https://www.cnblogs.com/bingrong/p/3169682.html
Copyright © 2011-2022 走看看