Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Doubt in Enthuware Questions

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In Enthuware Standard Test 1 we have the following questions.

a)Consider the code shown below.


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

a).Make the class UserData implement HttpSessionBindingListener
b).Make the class UserData implement HttpSessionAttributeListener

I selected b. but answer given is a. with below explanation.I think this is wrong.

HttpSessionAttributesListener is configured in deployment descriptor and this does not notify the object
that is being added to or removed from the session. It notifies the object that is registered to listen to such events.

Second Question


b)The implicit variable 'out' is same as returned by response.getWriter()

a.True
b.False

I selected True.Because out is of type javax.servlet.jsp.JspWriter extends java.io.Writer and response.getWriter
will return java.io.PrintWriter extends java.io.Writer.Answer given is false with below explanation

Initially, out is a new JspWriter object. This object may be different from the stream object returned from response.getWriter()
, and may be considered to be interposed on the latter in order to implement buffering (see Section JSP.2.10.1, "The page Directive").
This is the initial out object. JSP page authors are prohibited from writing directly to either the PrintWriter or OutputStream
associated with the ServletResponse .

I did check the Spec couldent get any clarity on this.

Thanks
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About First Question:

HttpSessionAttributeListener is configured in deployment descriptor and this does not notify the object
that is being added to or removed from the session. It notifies the object that is registered to listen to such events.


The container will notify a listener implementing HttpSessionAttributeListener when attribute are added/removed/replaced. This listener is configured in the deployment descriptor. If you want the containter to notify an attribute when it is being bound/unbound in/from a session, you make the attribute implement HttpSessionBindingListener. There's no need to configure anything in this case, as the container will automatically detect that the attribute implements HttpSessionBindingListener.

You'll also find a useful document about listeners here.
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

That means i have selected the correct option.is that correct?

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. UserData has to implement HttpSessionBindingListener.

 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In the Question we have

You need the UserData object, which is added to the session, to know whenever it is added to the session
automatically



Now the answer will be HttpSessionBindingListener.

If the Question was like

You need the UserData/UserData class/UserData Listener , which is added to the session, to know whenever it is added to the session
automatically



Now the answer will be HttpSessionAttributeListener.Is My understanding correct?

Thanks
[ November 19, 2008: Message edited by: raja ram ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use HttpSessionAttributeListener for the same purpose, using the HttpSessionBindingEvent passed in attributeAdded, but you would need a special method in UserClass to tell it that it was added to the session. I think the question would have been something like : "You need to track which attribute is added to the session automatically"
 
No more fooling around. Read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic