Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HFSJ Mock Exam

 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going through HFSJ 1st edition Q15.

Q:- Once a session has been invalidated, which HttpSession methods can be called on that session without throwing illegalState Exception?

Options -

A: invalidate
B: getAttribute
C: setAttribute
D: getServletContext
E: getAttributeNames

Answer: - Since the servletContext survives, getServletContext can be called successfully on an invalid session.

I am not so clear why? if an object is invalid now...how and why getServletContext servives. Trying to access this should give null pinter exception or illegalStateException.

Please clarufy this doubt
 
Kathiresan Chinna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When you call invalidate()
The session ID no longer exists.
The attributes are removed from the session object.

Kathir
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!