Interceptor+Cookie is used in SpringMVC to realize automatic login within a certain number of days.
After clicking on login, you can find that the page jumps to: http://localhost:9180/CookieDemo/user/index.html
At the same time, a cookie record value named "remember-me" is generated, and its value is: YWRtaW46YzhjYTU3NjktNDhjZi00NWQ4LTk4YzQtM2QzMDMwNWVlMWY5
If you use the online base64 decoding tool to decode it, you can find that the original text of this cookie value is:
It corresponds exactly to the record in the persistent_ logs table in the database:
Then, after exiting the browser, open the browser again to access: http://localhost:9180/CookieDemo/user/index.html
It can be found that the page can be accessed directly and is already logged in. At this point, our goal has been achieved.
(2) after testing login, jump back to the page you originally wanted to visit:
Delete the cookie of "remember-me" in the browser, or delete the record in the persistent_ logs table in the database, and then visit: http://localhost:9180/CookieDemo/user/callback.html after logging out
As you can see, the page has been automatically redirected to the login page
Then, enter the user name and password to log in, and you can find that after the login is successful, you can jump to the page we originally requested:
Attached: the complete source code of this test project:
Link: http://pan.baidu.com/s/1nvo72a9 password: dkxa
PS: the watermark in the above picture is the domain name of my personal blog, so please show mercy not to mark me as "reprinted article", thank you!