Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Wierd problem

Reply
Thread Tools

Wierd problem

 
 
suneet.taparia@gmail.com
Guest
Posts: n/a
 
      04-27-2006
Hi,

I'm facing a wierd problem in my code:

There's is a servlet that is having a service() and a doPost() in it
and this servlet is extented by a class that also has a doPost()
implemented.

What actually happens is that :

When request reaches my servlet then in the service() then I call
doPost() method but instead of calling the doPost of the servlet its
calling the doPost() of the child.

Can anyone explain why is this happening?

Thanks in advance

 
Reply With Quote
 
 
 
 
Ingo R. Homann
Guest
Posts: n/a
 
      04-27-2006
Hi,

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> There's is a servlet that is having a service() and a doPost() in it
> and this servlet is extented by a class that also has a doPost()
> implemented.
>
> What actually happens is that :
>
> When request reaches my servlet then in the service() then I call
> doPost() method but instead of calling the doPost of the servlet its
> calling the doPost() of the child.
>
> Can anyone explain why is this happening?


It's not a bug, it's a feature! That is exactly what is supposed to
happen, it's not weird at all. That's what's OO about.

If you do not want that the method of the "subclass" (not "child") is
called, then you must not "override" it. To avoid (in the "superclass")
that the method can be "override" in a "subclass", you can declare the
method as "final". (Of course, in your case that leads to a compiler
error in the subclass. You have to rename the method in the subclass.)

I strongly suggest to read some OO-Books!

Ciao,
Ingo

 
Reply With Quote
 
 
 
 
Paul Cager
Guest
Posts: n/a
 
      04-27-2006
(E-Mail Removed) wrote:
> There's is a servlet that is having a service() and a doPost() in it
> and this servlet is extented by a class that also has a doPost()
> implemented.
> ... ...
> When request reaches my servlet then in the service() then I call
> doPost() method but instead of calling the doPost of the servlet its
> calling the doPost() of the child.


If I've understood you correctly then this would seem to be normal
behaviour - an instance of the dervied class should call its own
(overridden) version of the doPost method. What is it you are trying to
achieve?

 
Reply With Quote
 
Luke Webber
Guest
Posts: n/a
 
      04-27-2006
(E-Mail Removed) wrote:
> Hi,
>
> I'm facing a wierd problem in my code:
>
> There's is a servlet that is having a service() and a doPost() in it
> and this servlet is extented by a class that also has a doPost()
> implemented.
>
> What actually happens is that :
>
> When request reaches my servlet then in the service() then I call
> doPost() method but instead of calling the doPost of the servlet its
> calling the doPost() of the child.
>
> Can anyone explain why is this happening?


Which class are you calling in your HTML? The child or the parent? As an
example, let's say the parent is called ParentServlet and the child is
called ChildServlet. If you call ParentServlet, you can expect to get
the result you seem to want, but if you call ChildServlet, that would
explain what you're seeing.

Luke
 
Reply With Quote
 
suneet.taparia@gmail.com
Guest
Posts: n/a
 
      04-28-2006
Thanks man .... I got your point....

 
Reply With Quote
 
suneet.taparia@gmail.com
Guest
Posts: n/a
 
      04-28-2006
Thanks man .... I got your point....

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wierd Problem Andrew C Wireless Networking 1 09-06-2005 04:31 AM
Cisco VPN and wierd Wireless problem (one card works, other won't) Russ Cisco 2 07-13-2005 08:38 AM
Wierd Problem with VPN from an 831 to a 3005 N. Hall Cisco 0 04-15-2005 08:03 PM
wierd 2501 and 2503 command history IOS problem... Trailboss Cisco 5 02-26-2004 09:22 AM
Re: Wierd NAT Problem Aaron Woody Cisco 1 11-11-2003 12:42 PM



Advertisments