• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in Enthuware Mock Exams Qs

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the follwing code:

//in file UserData.java
public class UserData
{
...data fields and methods...
}

//In file LoginServlet.java
public class LoginServlet extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
{
UserData userdata = loginUser(req);
req.getSession().setAttribute("userdata", userdata); //1
}
}

You need the UserData object, which is added to the session, to know whenever it is added to the session. What is the right way to accomplish this?


Options

Select 1 correct option.

1. Make the class UserData implement HttpSessionBindingListener


2. Make the class UserData implement HttpSessionListener
This interface is used when you are interested in session creation and destruction.

3. call some method on UserData object after //1.
Looks promising but you would have to call it in all the places. And this would be nonstandard too.

4. Make the class UserData implement HttpSessionAttributesListener


5. This cannot be done!



As per my understabding of qs the ans will be 1 and 4 , as we can acheive the desired resultwith both of these listener.

But by the site the ans is only 1 , so what will be the correct ans .
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpSessionAttributesListener has to be declared in web.xml because it's intended to be implemented by container level classes.

The container doesn't use reflection to work out which objects implement this interface, so you cant use it on an attribute. i.e ONLY HttpSessionBindingListener is the correct answer.
 
reply
    Bookmark Topic Watch Topic
  • New Topic