Java Servlets and HttpSessions

Very simple question. I have a portal containing several servlets, one of which takes care of registration (but only as an administrator). How to use HttpSessions between servlets to find out if an administrator is signed?

Thanks in advance!

+3
source share
3 answers

set attribute in session

session.setAttribute("isAdmin",true OR false);

At the time of logging in, select the user type and set it.

+2
source

Whenever your administrators sign insert something like session.setAttribute ("admin", "true");

session.getAttribute( "admin" ), ,

+3

I would save the full user object in the session.

http://download.oracle.com/javaee/1.3/api/javax/servlet/http/HttpServletRequest.html#getSession ()

You can access the session using this method. If you save the entire user in a session (or the user ID from your database), you can implement more advanced, role-based access later, as your application grows.

Hi

0
source

Source: https://habr.com/ru/post/1771957/


All Articles