on the login page, you create a session as follows:
HttpSession session = request.getSession(true);
this will create a session if none exists.
During the rest of the users activities, all other pages should use the
following:
HttpSession session = request.getSession(false);
This will return null if there is no valid session. So check for this.
If anything happens (i.e. the login fails or you go to the logout page),
do the following:
This will invalidate the session so that further getSession calls using false
return null.
This is the basic session process/life cycle.
The login itself, you can still do yourself, and if it fails, just invalidate
the session, as mentioned above. If it succeeds, then continue with the
site, and on the logout page, invalidate the session again.