Arjun Anand

+ Follow
since May 24, 2001
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Arjun Anand

Yes, You can. You have to provide a Custom Renderer to display the items as checkboxes instead of Labels (which is the default).

20 years ago

Originally posted by Paul Stevens:
Yes you need to create a custom component.

Well, I guessed so. Any Hints in this direction would be helpful. Like whether I need to extend
Component class or its enough that I extend JList? Also If anybody had worked on such kind of problem, please give your insights as to what were the problems you faced etc..
20 years ago
How can I construct a Listbox which can display items horizontally as opposed to the usual way of having items vertically. Since I'm migrating the application from Delphi to Java, I'm required to preserve the User Interface. The current Delphi UI has a Listbox control (whatsoever its called in Delphi) which displays items horizontally. I need to duplicate the same in Java. Do I need to create a custom component or is there one available in the JDK itself?
20 years ago

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 ]

Then Sun would have deprecated the listener, wouldn't they?

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.

That is what even I thought. But wanted to confirm if my understanding is right.
Both ServletContext and HttpSession objects can hold attributes. According to Servlet 2.3 spec, the difference between the attributes in ServletContext and HttpSession is that

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..

Is there any other difference between ServletContext and HttpSession attributes which i'm missing?

Also in Servlet Spec 2.3 in Chapter 10, Application Lifecycle Events it states,

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.

Here it says the Session is scoped to the particular VM servicing the session requests which means I cannot use sessions to store attributes to be shared, in a distributed container.
This contradicts the previous one. Which one is correct? Somebody throw lights in this.
Thanks Madhav and Chintan for your prompt replies.
And Congratulations Chintan on becoming a SCWCD. Way to go pal.
I know the working of HttpSessionBindingListener and HttpSessionAttributeListener. But my question is:
Why should I need a HttpSessionBindingListener to notify the object. Instead I can use a class that implements HttpSessionAttributeListener and find out the object that was affected from the event object and then take appropriate action on the affected object. Sort of a controller class listening for all the events and dispatching it to the respective objects.
Hope I was clear in my question.
Any comments

Originally posted by Chintan Rajyaguru:
Good question:
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)
session.removeute ("Object", MyObject)
and so on, methods valueBound and/or valueUnbound (defined in HttpSessionBindingListener, implemented in MyObject are called)
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);
session.removeAttribute ("anything", AnyObjectNotOnlyMyClass);
indicates change in the list of attributes and hence appropriate method is called
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.
[ January 04, 2002: Message edited by: Chintan Rajyaguru ]

What is the difference between HttpSessionBindingListener and HttpSessionAttributeListener other than that Attributelistener is invoked for adding,replacing and removing objects in session and Bindinglistener is invoked when an object is bound (adding) or unbound (removing) from a session. I dont understand the reason of having 2 Listener classes serving the same purpose.
Clarifications please.
Can anybody Please explain the below paragraph. I'm totally lost
From the Servlet 2.3 Spec:

Session Scope
HttpSession objects must be scoped at the application (or servlet context) level.
The underlying mechanism, such as the cookie used to establish the session, can be
the same for different contexts, but the object referenced, including the attributes in that object, must never be shared between contexts by the container. To illustrate this requirement with an example: if a servlet uses the RequestDispatcher to call a servlet in another web application, any sessions created for and visible to the callee servlet must be different from those visible to the calling servlet.

I understand this concerns only Servlet Container providers and not Application Devlopers. Nevertheless, in a bid to understand, I fail to see how a session can be scoped at an application level.
Further, it says the cookie can be the same but the object cannot be so.
Any lights in these points please

The JLS abt. the instanceof operator says that.


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.

Your answer lies in the 2nd Para. The result of the RelationalExpression is true if the reference could be cast to the ReferenceType given that the lvalue(the relationalexpression) is not null.

Now lets analyze ur question

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?

The hierarchy goes like this.
As per the language a subclass instance can be implicitly cast to a superclass instance.

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?

Hence an object o of any class be it A or B or C, will return true for the expression:
o instanceof A coz an object of a subclass gets casted to a superclass implicitly. Hence for the above question to return true the object o should be an instance of Class B and not an instance of any of its subclasses here it means C. Hence option b is the correct answer.

Originally posted by Mapraputa Is:

Personally I feel that any good programmer has to be an evening person. Hate this morning folk They 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...)

What makes you think so Map? Not that i'm a morning person, I too am an evening guy. But the reason i prefer to work in the eve's is that there isn't much of disturbance. But Ideas. hmmm i have no time bar in that area. Not much arise from my Cerebrum. On the same lines most of the Computer geeks(not just good Programmers) are loners with no bar in time.
20 years ago
Actually you dont need a finally clause if you are catching the appropriate exceptions and want to return a value irrespective of whether that exception is thrown or not. The following code will also do fine.

public int intFunction() {
int k = 10;
try {
} catch ( Exception e) {}
return k;

The above code also returns the value 10.

Originally posted by William Brogden:
Have you defined a "web application" for your servlets in the server.xml file?

I dont know. How do you do that?
20 years ago

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.

Hi Tim,
I could not understand what you exactly mean by defining the serlvets. If you are talking about registering the servlets in web.xml then yes I have done it using the <servlet></serlvet> tag and also i have given alias using the <url-pattern></url-pattern> tag for each and every serlvet. I'm currently breaking my head trying to figure out what could be the cause for this problem.
The following are the options i have tried till now:
1. I put my entire directory into the webapps directory under Tomcat home and change the context path. Still to no avail.
2. I copied the web.xml file found in the examples directory under Tomcat_Home/Webapps and changed the <servlet></servlet> tags to reflect my Servlet names. Not working.

20 years ago
Hi guys!!
I have installed Tomcat 4.0 and configured the server.xml and the web.xml of my application accordingly. My jsp pages are working properly, but the Servlets aren't working. It simply says the Servlet is not found. But the servlets in the examples directory are working.
Is there anything else that i need to configure.
Please help.

20 years ago