Originally posted by Paul Stevens:
Yes you need to create a custom component.
Originally posted by Rohit Poddar:
Let me try to give an argument why do we have these two listener and let's see if I succeed![]()
HttpSessionBindingListener was there before Servlet 2.3 came out. And HttpSessionAttributeListener, which serves a broader purpose was added in 2.3. And now to maintain backward compatibility Sun must have left HttpSessionBindingListener in there.
Any takers ?
[ January 10, 2002: Message edited by: Rohit Poddar ]
Originally posted by Tom Arons:
I think these specs are maybe a detailed explanation to say that sessions can migrate to other VM's. Each VM has a separate instance of ServletContext and so do not rely on state information in ServletContext.
SRV.3.4.1 Context Attributes in a Distributed Container
Context attributes are local to the VM in which they were created. This prevents ServletContext attributes from being a shared memory store in a distributed container. When information needs to be shared between servlets running in a distributed environment, the information should be placed into a session, stored in a database, or set in an Enterprise JavaBeans component..
SRV.10.6 Distributed Containers
In distributed web containers, HttpSession instances are scoped to the particluar VM servicing session requests, and the ServletContext object is scoped to the web
container’s VM. Distributed containers are not required to propogate either servlet context events or HttpSession events to other VMs. Listener class instances are scoped to one per deployment descriptor declaration per Java virtual machine.
Originally posted by Chintan Rajyaguru:
Good question:
HttpSessionBindingListener:
If an object implements HttpSessionBindingListener, it is notified when it is bound to or unbound from a session. For example,
MyObject implements HttpSessionBindingListener
{
// class definition
}
If I call
session.setAttribute ("Object", MyObject)
or
session.removeute ("Object", MyObject)
and so on, methods valueBound and/or valueUnbound (defined in HttpSessionBindingListener, implemented in MyObject are called)
HttpSessionAttributeListener:
When any class implements HttpSessionAttributeListener interface it is notified when any change in the attribute list of session occurs. For example
MyClass implements HttpSessionAttributeListener
{
// implementations of methods
}
session.setAttribute ("anything", AnyObjectNotOnlyMyClass);
or
session.removeAttribute ("anything", AnyObjectNotOnlyMyClass);
indicates change in the list of attributes and hence appropriate method is called
DIFFERENCES:
Implementing HttpSessionBindingListener works only for the object that implements it whereas implementing HttpSessionAttributeListener listens to any attribute added, removed or replaced.
Hope this helps. This is important. Let me know if this is not clear, I will explain it again with simple words. I had questions from these topics.
Chintan
[ January 04, 2002: Message edited by: Chintan Rajyaguru ]
15.20.2
Type Comparison Operator instanceof
The type of a RelationalExpression operand of the instanceof operator must be a reference type or the null type; otherwise, a compile-time error occurs. The ReferenceType mentioned after the instanceof operator must denote a reference type; otherwise, a compile-time error occurs.
At run time, the result of the instanceof operator is true if the value of the RelationalExpression is not null and the reference could be cast (�15.16) to the ReferenceType without raising a ClassCastException. Otherwise the result is false.
If a cast of the RelationalExpression to the ReferenceType would be rejected as a compile-time error, then the instanceof relational expression likewise produces a compile-time error. In such a situation, the result of the instanceof expression could never be true.
Given classes A,B and C where B is subclass of A and C is a subclass of B, which one of these boolean expressions correctly identifies when an object o has actually been instantiated from class B as opposed to from A or C?
Select one right answer.
a.) (o instanceof B) && (!(o instanceof A))
b.) (o instanceof B) && (!(o instanceof C))
c.) !((o instanceof A) | | (o instanceof B))
d.) (o instanceof B)
e.) (o instanceof B) && !((o instanceof A) | | (o instanceof C))
Correct ans given is option b
pls tell me why b is correct and what is the question asking for?
rajashree.
Originally posted by Mapraputa Is:
Personally I feel that any good programmer has to be an evening person. Hate this morning folkThey are boring, intrusive and suffer from lack of intelligence. No wonder, all good ideas come to us after 11 p.m. - they just miss them totally!
(now run under cover very quickly...)
Originally posted by William Brogden:
Have you defined a "web application" for your servlets in the server.xml file?
Bill
Originally posted by Tim Holloway:
Have you explicitly defined the servlets in web.xml? Older Tomcats could pick them up implicitly, but IMHO that was a security risk and maybe it's been turned off now.