Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Wierd problem

Thread view: 
suneet.taparia@gmail.com - 27 Apr 2006 08:38 GMT
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
Ingo R. Homann - 27 Apr 2006 10:11 GMT
Hi,

> 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()
[quoted text clipped - 7 lines]
>
> 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
suneet.taparia@gmail.com - 28 Apr 2006 06:59 GMT
Thanks man .... I got your point....
Paul Cager - 27 Apr 2006 10:19 GMT
> 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()
[quoted text clipped - 3 lines]
> 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?
suneet.taparia@gmail.com - 28 Apr 2006 06:59 GMT
Thanks man .... I got your point....
Luke Webber - 27 Apr 2006 12:41 GMT
> Hi,
>
[quoted text clipped - 11 lines]
>
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.