• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Logout problem.

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

I have been reading Kathy Sierra Head First JSP/Servlets book and i am very happy to learn it the way the chapters are organized.

Recently i completed Conversational State chapter and tried having my hands on Sessions in Web in which i am stuck at 1 point, i created the following.

1. Login.jsp which would have a username and password.
2. LoginAction.java which would set the request parameter to session attribute and this LoginAction class would forward the request using RequestDispatcher to result.jsp.
3. result.jsp has a Greeting for the user registered saying "Welcome, " and it works like a dream.

Now my problem.

Result.jsp has a link to logout.jsp, Below is the code of result.jsp



and then logout.jsp has the following code :



What i was expecting was it would show "Welcome,Guest" because when i said session.invalidate, it made the session as null and on checker.jsp i am checking for session==null , however it showed Welcome null. I am not sure why session.invalidate() on Logout.jsp did not return null.

Can you all please help me.

Below is checker.jsp for reference.



Yogendra N Joshi.
[ December 25, 2008: Message edited by: Yogendra Joshi ]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that is happen because in JSP, session is never null. It is an implicit object, so I guess HttpServletRequest.getSession() is always called.

Arie Prastowo
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need HttpSession#isNew() rather than testing it against null.

That said, your logout.jsp is bogus. Check your appserver logs. There is an IllegalStateException in it.
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Thanks a lot for your valuable suggestion , session.isNew did the work. It now correctly returns WElcome Guest.

I would also check if session==null had IllegalStateException in the logs.

Regards
Yogendra
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic