May I ask a question about how the front end maintains the information of a current user?

in the past, when I used JSP, I could save the information to session on the back end, and then directly use <% = > on the jsp page to get each of the information I want that represents the current user. Now I am using a pure html+ssm framework instead of a template. How can I indicate the information of the user after logging in?


user's login information can be saved for a limited time, except for cookie and session,localStorage. The;; cookie character length used by localStorage for persistence is limited and is not secure; session relies on the backend; the front end generally uses localStorage to store user information, instead of judging each background or front-end request

:
localStorage.setItem('key',value)

localStorage.getItem('key')

you can use localStorage at the front end to save the unique identity of the user. At the same time, you can use things like redis on the server side to maintain a table of logged-in users, and set an expiration time for each record in redis. Each front-end request needs to carry a locally saved user identity in body, and the server can use a filter to Filter the request.


cookie,localstorage


judge according to sessionstorage, store user information in sessionstorage when logging in, and judge whether to log in according to this information. If you clear it when you log out, you will OK it. If the browser is closed, it will be cleared automatically

.
Menu