Question

Very basic question. I have a portal containing several servlets, one of which takes care of logging in (but only as an admin). How do I use HttpSessions between Servlets to know if the admin is signed in?

Thanks in advance!

Was it helpful?

Solution

set an attribute in session

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

At the login time decide the user type and set it.

OTHER TIPS

Whenever your admin users signs in put something like session.setAttribute("admin","true");

check this as session.getAttribute("admin") to see if admin is logged in

I'd store the complete user object in the session.

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

You can gain access to the session through this method. If you store the whole user in the session (or the user-id from your database), you can implement a more refined, role-based access later on as your application grows.

greetings

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top