简体   繁体   English

检查用户是否已经登录

[英]Check whether the user is already logged in or not

I am currently working on a web application developed on Servlet-JSP MVC which runs on a internal server and the problem scenario is as below. 我目前正在使用在内部服务器上运行的Servlet-JSP MVC开发的Web应用程序,问题情况如下。

If the end user enter the site url,the application will ask for login credentials and i am checking the credentials in a LoginController. 如果最终用户输入站点URL,则应用程序将询问登录凭据,而我正在检查LoginController中的凭据。

Consider the situation when the user enter the credentials and login into the application and then closes the browser window,if the user again types the url it will again ask for the login credentials. 考虑以下情况:用户输入凭据并登录到应用程序,然后关闭浏览器窗口,如果用户再次键入url,它将再次询问登录凭据。

Now i want my application to remember whether a user is logged in or not,only ask for the login credentials if the user is already not logged in. 现在,我希望我的应用程序记住用户是否已登录,如果用户尚未登录,则仅询问登录凭据。

How can i implement this?Any suggestions on what can be done will be helpful. 我该如何实施呢?关于可以做什么的任何建议都会有所帮助。

Thanks in advance, 提前致谢,

The browser has to store the information if the user is logged in. You could use cookies for that. 如果用户已登录,浏览器必须存储信息。您可以为此使用cookie。

You can simply store a value that says: No need to check for password. 您可以简单地存储一个表示以下内容的值:无需检查密码。 Or you can store the username in the cookie and send it to the server which checks if the user is logged in and then replies the result to the browser. 或者,您可以将用户名存储在cookie中,然后将其发送到服务器,服务器将检查用户是否已登录,然后将结果答复给浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM