In my JSP application, I want to keep track of the user that's logged in.
When the user tries to log in, I use database transactions in a UserManager
class to verify that the entry exists (I'm not aiming to make a very secure site, most of this is for learning).
That UserManager
class constructs a User
instance object out of the retrieved information on the user (i.e. their name, age, photo, etc).
I use this object to efficiently call prepare the presentation on the user's home page, after the log in is successful.
The trouble is, I don't know how to keep this User
object alive for the duration of the whole session with the user. For example, if he goes to other pages, I still want to be able to call
user.getPhoto()
or
user.getLastName()
without complicated database queries each time.
Is there any way to do this?