This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

HFSJ 1st edition mock exam question

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a HFSJ 1st edition mock exam question .When I took the exam I didn't get it right , someone please explain the answer.

What type of listener could be used to log the user name of a user at the time
that she logs into a system? (Choose all that apply.)

A. HttpSessionListener

B. ServletContextListener

C. HttpSessionAttributeListener

D. ServletContextAttributeListener

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a ServletContextListener. That one fires events when the app is being deployed, before servicing any requests. And, sessions are created automatically and you may not want the user to log in immediately. That leaves HttpSessionAttributeListener and ServletContextAttributeListener.

Note that using the ServletContext for logging seems like a terrible idea, but you can make it work.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpSessionListener would be ideal I think.

HttpSessionAttributeListener may also be helpful in logging .

I doubt how ServletContextListener can be used to log user login. The callback methods for this interface are for initialization and destruction of the context.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

if the question asks to select one: i'll go for HttpSessionListener. the user name can be logged in the listener's sessionCreated().
if it asks to select 2 then i'll go for HttpSessionListener and HttpSessionAttributeListener. the first one logs all the user logged in. the 2nd one can be used to log the user for his entire session period.
 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer is HttpSessionAttributeListener , I went for HttpSessionListener

Book has following explanation

-Option A is incorrect because the user name would not be
known when the session is initially created. Since logging is
desired at the time of the login, the listener’s invalidation
and timeout methods would not be helpful.
(API)
-Options B and D are incorrect
because these listeners are used for
servlet-context notifications.

I didn't understand why A is not a correct option , session will be created when the user first logged in .HttpSessionListener seems to be correct choice.

Archana
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic