Wierd problem

Discussion in 'Java' started by suneet.taparia@gmail.com, Apr 27, 2006.

  1. Guest

    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
    , Apr 27, 2006
    #1
    1. Advertising

  2. Hi,

    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
    Ingo R. Homann, Apr 27, 2006
    #2
    1. Advertising

  3. Paul Cager Guest

    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?
    Paul Cager, Apr 27, 2006
    #3
  4. Luke Webber Guest

    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
    Luke Webber, Apr 27, 2006
    #4
  5. Guest

    Thanks man .... I got your point....
    , Apr 28, 2006
    #5
  6. Guest

    Thanks man .... I got your point....
    , Apr 28, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott M.

    Re: Wierd SessionState Problem

    Scott M., Aug 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    413
    Scott M.
    Aug 30, 2003
  2. Dean
    Replies:
    1
    Views:
    361
  3. Flores Eken
    Replies:
    1
    Views:
    339
    Flores Eken
    Dec 26, 2003
  4. anony

    Wierd .NET / IIS problem

    anony, Jun 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    353
    Trevor Benedict R
    Jun 19, 2004
  5. Michael
    Replies:
    0
    Views:
    361
    Michael
    Nov 16, 2005
Loading...

Share This Page