Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ 1st edition mock exam question

 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • 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

 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • 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.
 
Ranjit Gopinathan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • 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.
 
Abdul Rahman
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic