aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt in Enthuware Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt in Enthuware Questions" Watch "Doubt in Enthuware Questions" New topic
Author

Doubt in Enthuware Questions

raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
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
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

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

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

No. UserData has to implement HttpSessionBindingListener.

raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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"
 
Don't get me started about those stupid light bulbs.
 
subject: Doubt in Enthuware Questions