I am creating a website using Java EE.
I have created a table in a PostgreSQL database for the user data(username, password, role). I want to make a security realm or something like that in which to put some of the servlets. If a user sends a request to one of the servlets in the security realm and is not loged in, I want to redirect them to the login page.
The problem that I am having is that I don't know how to verify if the user is loged in or not when the request is received on the server. Should I use a session id or cookie? I've also searched a lot on form based authentication but I haven't found a way to compare the received data with the data stored in my database.