Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP logout and clear cache on browser (security)

Status
Not open for further replies.

HacH

Programmer
Dec 24, 2002
27
GB
Hello all,

I am having a problem implementing a logout feature in my website. I have a login page, once the user logs int their userId is stored to a session var as session.addAttribute("userId", userId); upon entry to every page on my site I need to check if user is logged in (has a valid session) if not redirect them to the login page. I tried the following but it gives me a nullpointerexception, due to the fact that I am referring to other session var and form properties in the same page.

if (null == session.getAttribute("userID") {
redirect to page....
}

I also want to clear the browser cache for all the pages a user has visited on my site once they logout.

Can anyone please help, I am fairly new to Java and dont know any other way of doing this. If anyone knows a better way of doing it I would really appreciate it

Thanks in advance
 
Your post contains a missing parenthesis

if (null == session.getAttribute("userID") {

if (null == session.getAttribute("userID")) {

-pete
 
Thanks Palbano,

Sorry, I made a mistake when typing the thread. I have tried this, it works only if I check for all the session attributes that are being used on oach page. For example I have userID, accessLevel and other's depending on which page you are on. The problem is that if the userID attribute is null the rest of the code carry's on executing and I get a NullPointerException as some other attribute or parameter is not found..what I want is the page to stop executing within the if (null == session.getAttribute("userID")) { staatement and go to the error page, without trying to execute further code.


I have tried the below code and it works but it will make every page messy:

boolean isLoggedIn = true;
if (null == session.getAttribute("userID")) {
isLoggedIn = false;

}

if (!isLoggedIn) {
<jsp:page fowd...>
} else {
execute resto fo code on this page
...
}

Is there a way to make the jsp skip all other code and go straight to the error page rather than the method above.

Thanks

Hach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top