请记住我在jsp登录页面 [英] Remember me in jsp login page

查看:219
本文介绍了请记住我在jsp登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有登录屏幕,我通过检查数据库中的凭据来验证用户身份。但是我如何实现记住我复选框?就像在gmail 中一样,请记住我(保持登录状态)。我正在使用 sign.jsp Auth servlet(doPost) oracle 10g ee 用于身份验证。

I have a login screen and i am authenticating users by checking credentials from database. But how can i implement Remember me check box? Like in gmail remember me(stay signed in) is present. I am using sign.jsp and Auth servlet (doPost) and oracle 10g ee for authentication.

推荐答案

为此可以使用 cookies

在你的servlet响应处理程序(doPost,doGet等)中,按以下方式创建一个cookie -

In your servlet response handler (doPost, doGet etc.) create a cookie in the following way -

if(remember_me_is_checked)
{
    Cookie c = new Cookie("userid", userId.toString());
    c.setMaxAge(24*60*60);
    response.addCookie(c);  // response is an instance of type HttpServletReponse
}

要阅读它们,你可以使用这样的事情 -

To read them, you can use something like this -

Cookie[] cookies = request.getCookies();     // request is an instance of type 
                                             //HttpServletRequest
boolean foundCookie = false;

for(int i = 0; i < cookies.length; i++)
{ 
    Cookie c = cookies[i];
    if (c.getName().equals("userid"))
    {
        string userId= c.getValue();
        foundCookie = true;
    }
}  

这里 Cookie class。

这篇关于请记住我在jsp登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆