ssm框架得用户登陆

**

.用户登陆

**我是一个小白一下是对用户登陆系统得总结,希望其他人用得上,
思路:
获取登陆页面表单提交的userName 和password
到userController层将获取的userName拿到数据库查询,该用户是否存在,有该用户的话在前台获取的password与后台查询到的password是否一致

图解如下:

                   前端
登陆

登陆投票系统







    <table style="text-align: center">
        <div class="input-group">
        <div class="col-3 col-form-label">
            <label class="formLabel" for="password"><s:message code="user.password"></s:message></label>
        </div>

            <div class="col-8">
            <input id="password" class="form-control" name="password" type="password">
            </div>
        </div>
    </table>
 <br>
<br>
<br>
<div style="text-align: center ;padding: 5px">

        <input type="submit" value="登录" style="background-color: darkseagreen" />

    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;

    <input type="button" style="background-color: darkseagreen" value="重置" onclick="clearForm()"/>
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;
    &nbsp; &nbsp;

    <input type="button" style="background-color: darkseagreen" value="注册" onclick="window.location.href='/user/insert'"/>

</div>
</table>
 </div>

控制层
@RequestMapping("/login")
public String login(){
return “home/loginUI”;
}

@RequestMapping("/findUserName")
@ResponseBody
public ModelAndView findUserName(User user,
@RequestParam(value=“userName”)String userName,
@RequestParam(value =“password”)String password,
HttpSession httpSession) {
String passwords=password;
String userNames=userName;
user= userService.findUserName(userNames, passwords);
httpSession.setAttribute(“ss”,user);
ModelAndView modelAndView =new ModelAndView();
if (user !=null) {

modelAndView.setViewName(“home/home”);
//modelAndView.addObject(“ss”,userName);
return modelAndView;
} else {
modelAndView.setViewName(“home/loginUI”);
return modelAndView;
}
}

service层

@Override
public User findUserName(String userName, String password) {
    User user=userDao.findUserName(userName);
    if (user !=null && user.getPassword().equals(password)) {
        return user;
    }
    return null;
}

谢谢!参考

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值