I want to prevent unathorized users to access directly using URL in my application
When the user logs in, do you put that user in the session?
String username;
String password;
// check the database to see if the user is valid.
if (yes) {
request.getSession().setAttribute("USER",username);
}
When the user logs out do you do this:
request.getSession().setAttribute("USER",null);
And my suggestion would be to put this check in all of your pages:
String username = (String)request.getSession().getAttribute("USER");
if (username==null) {
// unauthorized user
// redirect to log in page
}
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
Offline 3,260 posts
since Dec 2007