Cookie保存账号密码

<body>
<%
    String loginname = "";
    String password = "";
    Cookie cookie[] = request.getCookies();
    if (cookie != null) {
        for (int i = 0; i < cookie.length; i++) {
            if (cookie[i].getName().equals("loginname")) {
                loginname = cookie[i].getValue();
            }
            if (cookie[i].getName().equals("password")) {
                password = cookie[i].getValue();
            }
        }
    }
%>
    <div align="center" style="margin-top:100px"> 
        <div id="p" class="easyui-panel" title="登录" style="width:300px;height:220px;padding:10px;" align="center">
            <form action="goHome" method="post">
                用户名:<input type="text" name="loginname" value="<%=loginname %>"/>
                密 码:<input type="password" name="password" value="<%=password %>"/>
                记住账号密码:<input type="checkbox" value="yes" name="status"/><br/><br/>
                <input type="submit" value="登陆"/>
            </form>
        <input type="button" value="注册" onclick="goDesigner()"/>
        </div>
    </div>
</body>

 

@RequestMapping(value="/goHome")
public String goHome(User user,HttpSession session,HttpServletRequest request,HttpServletResponse response){
    User user2=userService.checkLogin(user);
    String status=request.getParameter("status");
    if(user2!=null){
        session.setAttribute("user", user2);
        if(status!=null&&!"".equals(status)){
            if("yes".equals(status)){
                Cookie cookie_userName=new Cookie("loginname",user.getLoginname());
                Cookie cookie_password=new Cookie("password",user.getPassword());
                cookie_userName.setMaxAge(5*60);
                cookie_password.setMaxAge(5*60);
                response.addCookie(cookie_userName);
                response.addCookie(cookie_password);
            }
        }
        return "home";
    }else{
        return "fail";
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值