码迷,mamicode.com
首页 > Web开发 > 详细

关于面试问到ajax与SSM框架,登陆验证

时间:2018-11-07 14:05:30      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:ESS   async   而不是   button   control   inpu   orm   action   get   

不比比,直接上代码

JSP页面,

<body>
<form action="" method="post" >
<input name="username" type="text" id="username" />
<input name="password" type="password" id="password" />
<button id="login" onclick="requestJson()" type="button">登录</button>
</form>
 

<script type="text/javascript">
       function requestJson(){
            var name =$("#username").val();
            var pwd =$("#password").val();
           if(name==""){
                alert("用户名不能为空!");
                return false;
            }
            else if(pwd==""){
                alert("密码不能为空!");
                return false;
            }else{
$.ajax({
                type:‘post‘,
                url:‘login.do‘,
                dataType:"json",//注意使用的是打他dataType,而不是Content-Type
                async: true,
                data:{username:name,password:pwd},
                success:function(data){
                   if(data==null){
                       alert("没有这个用户!")
                   }
                   else{
                       alert("登录成功")
                       window.location.href ="index.jsp";
                  }
                }
            });
           }
}
   </script>
</body>

Controlle层


@RequestMapping("login")
@ResponseBody
public User loginto(User user) {
System.out.println("username:"+user.getUsername());
System.out.println("password:"+user.getPassword());
User users=userservice.login(user.getUsername(), user.getPassword());
System.out.println(users.getUsername());
return users;
}
}

关于面试问到ajax与SSM框架,登陆验证

标签:ESS   async   而不是   button   control   inpu   orm   action   get   

原文地址:https://www.cnblogs.com/DIVEY/p/9921985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!