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

EPractice Lab review exam 1 : about valueUnbound() is called after the getAttribute of HttpSession?

 
Himai Minh
Ranch Hand
Posts: 1398
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The valueUnbound method must be called ____ the object is no longer available via the getAttribute method of the HttpSession interface.
a. before
b. after
Given answer: after


I think the valueUnbound method (of HttpSessionBindingListener) is called after the removeAttribute of the HttpSession or the invalidate() of HttpSession.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2778
174
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer given by the mock is correct.

From the Servlet 3.0 specs:
7.4 Binding Attributes into a Session
The valueUnbound method must be called after the object is no longer available via the getAttribute method of the HttpSession interface.
 
Himai Minh
Ranch Hand
Posts: 1398
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Frits, thanks for your reply.
But it does not make sense to me when it says "when the object is no longer available via getAttribute..."
I tried this:



Output from the servlet:

Bound the attribute: Dog : com.nullhaus.Dog@28c540
Add the attribute og:com.nullhaus.Dog@28c540
Remvoing the dog:
Unbound the attribute : Dog : com.nullhaus.Dog@28c540
remove the attribute og:com.nullhaus.Dog@28c540
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2778
174
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can test this part of the specs by trying to get the attribute from the HttpSession inside the valueUnbound method, like:

 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!