logout problem

Reply

Join Date: Mar 2006
Posts: 9
Reputation: sandy183 is an unknown quantity at this point 
Solved Threads: 0
sandy183 sandy183 is offline Offline
Newbie Poster

logout problem

 
0
  #1
Jun 5th, 2006
hi,
i'm trying to build a web page which permits the user to login before accessing the contents of the site. the login works fine (i did it using jsp), but i am not able to logout properly, that is, when i click on a "logout" hyperlink, it sends me to the proper page, but when i do "back" on my explorer, it gives me the previous page again. so my logout is pointless.

can anyone tell me how to prevent this from happening please?i don't know if i should use jsp, javascript or html to do this.
i need this urgently for my project.
thanks for replying as quickly as possible.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,277
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 242
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: logout problem

 
0
  #2
Jun 6th, 2006
I assume your login assigns a session. If so, than on logout do
session.invalidate() Pushing back on the browser may still show the
site but it should only be a version of the site in the cache. If the user
tries to actually submit anything, or reload the site, it should not work.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 9
Reputation: sandy183 is an unknown quantity at this point 
Solved Threads: 0
sandy183 sandy183 is offline Offline
Newbie Poster

Re: logout problem

 
0
  #3
Jun 6th, 2006
Originally Posted by masijade
I assume your login assigns a session. If so, than on logout do
session.invalidate() Pushing back on the browser may still show the
site but it should only be a version of the site in the cache. If the user
tries to actually submit anything, or reload the site, it should not work.
actually i didn't use session, i did the login using pure java code by matching the username and password from the database, then just put it in the jsp code in my web page.
is session secure?if you have a working piece of code using session can you send me please?i need this urgently for my project. thanks for your help!
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,277
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 242
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: logout problem

 
0
  #4
Jun 6th, 2006
on the login page, you create a session as follows:

  1. 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:

  1. 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:

  1. session.invalidate();

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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 9
Reputation: sandy183 is an unknown quantity at this point 
Solved Threads: 0
sandy183 sandy183 is offline Offline
Newbie Poster

Re: logout problem

 
0
  #5
Jun 6th, 2006
Originally Posted by masijade
on the login page, you create a session as follows:

  1. 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:

  1. 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:

  1. session.invalidate();

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.
i tried using the HttpSession session = request.getSession(true);
i just have to put it between <% %> at the start of the page right? well its giving me the error: duplicate session variable. am very new to jsp, sorry if i seem a bit dumb
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 5
Reputation: skoiloth is an unknown quantity at this point 
Solved Threads: 0
skoiloth's Avatar
skoiloth skoiloth is offline Offline
Newbie Poster

Re: logout problem

 
0
  #6
Aug 10th, 2006
First you check for the User name and password submitted from the login page , after validating the values submitted by the user , set a flag if the user is valid (successful login)
Like session.setAttribute("flag","true");
then put a condition down to forward the page .
your logout button should take you to the page where session.invalidate(); get called
now your logout function should happen

l
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2
Reputation: shajidbasha is an unknown quantity at this point 
Solved Threads: 0
shajidbasha shajidbasha is offline Offline
Newbie Poster

Re: logout problem

 
0
  #7
Dec 12th, 2007
Hi to all. I have tried the code:

session.invalidate();

But still i am able to archive my solution.
When i click back button. Its still going to the previous page.

Plz any one can help me on this.
Advance thanks.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,277
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 242
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: logout problem

 
0
  #8
Dec 12th, 2007
Have you tried "reloading" that page, or is it simply a static version cached by the browser?

If you are able to "reload" the page, then I am willing to bet that you are using getSession(true) to retrieve the session (in which case you are creating a new session if one does not already exist).

The static, cached page you can't really do anything about (from the server). You can set response headers and pragmas (Google no-cache and expires) to try and prevent it, but the browser does not have to follow these. Or you can use some JavaScript to play with the history, but the browser may have this deactivated.
Last edited by masijade; Dec 12th, 2007 at 3:47 am. Reason: typo (and probably still more left over)
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2
Reputation: shajidbasha is an unknown quantity at this point 
Solved Threads: 0
shajidbasha shajidbasha is offline Offline
Newbie Poster

Re: logout problem

 
0
  #9
Dec 12th, 2007
Hi Masijade thanks for your reply. I am using only an static page. I want to use only userName and password fields only as you can see some mailling websites. How can i get that? Plz can you help me.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC