Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to check if session exists?

 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I've written this code which (i honestly know) is completely inefficient , but anyway... i'm trying to use sessions to determine whether a user is logged in or out... but my super inefficient code isn't doing what i want

here it is..


Problem:
When i click on the logoff link, it takes me back to the same option to logoff! and thus it is not recognising that the object has been invalidated when the link was clicked! (although i've tested it to see if it is executing the logoff else statement and it was!)
and so if the session has indeed been invalidated, should itbe executing this else statement


Thanks for trying really hard to understand my code
HannaH
[ December 03, 2007: Message edited by: H Melua ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've found it's a lot simpler to test for the existence of an object bound to session than to test for the session itself.



JSPs, by default, create a session so I just assume that there is one and only use getSession() (no arguments) to obtain a reference to it.


Also, these days, it is recommended that this type of logic be factored back into a plain old Java object and controlled from a servlet. Life gets easier once you've moved all of your logic out of the JSPs.
[ December 03, 2007: Message edited by: Ben Souther ]
 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
:shocked: :shocked: :shocked:

oh my goodness!!! that workssssss

I should've asked days ago!!!

Thank you "VERY" much, that really drove me nuts!! I thought if i do it this way after i've invalidated the session, it will throw an exception!

Some kind 1 in this forum has advised me to use servlets before, but i'm not getting time to read about them, the course i'm doing is really intensive!!

oh well, life is dragging, and again
thank you very much.................
HannaH
[ December 03, 2007: Message edited by: H Melua ]
 
Nguyen Duy Lam
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for this post, it working now...
I was looking for a long time..nice job
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic