On Tue, 20 Jun 2000, Manisha Menon wrote:

> Hi,
> Thank you for your response.
>
> If that is the case, I can code service() method in the servlet2,
> right?  Why should I code doGet() and doPost() separately and call
> doPost() from doGet() method?

This has been discussed a number of times before on this list.
Suffice it to say that overriding service() is a bad idea, and you're
better off overriding/implementing doGet() and/or doPost().  Check the
list archives for details (basically the default service() provides a
lot, and it's silly to throw it all away).  If you are OK with having
the same behavior with GET and POST, there is nothing wrong with
implementing one of them and having the other one call it (or you
could have them both call some other method).


> Is there some way, where I can call doPost() method can be invoked
> directly from another servlet?

I would ask you to look more closely at why you want to do this,
there's a decent chance it means something is wrong with your design.
That is, why do you want to have one servlet call another's doPost()
method?  If it's to take advantage of some functionality that that
method already implements, perhaps the better solution is to have a
third class, perhaps not a servlet at all, but a standalone class of
some sort, that implements that functionality for both servlets.  If
it's to call that servlet as a normal HTTP request/response
transaction, then perhaps you should be using RequestDispatcher or
(Http)URLConnection.


> Or I want to call doPost() method of the same servlet?  Let us say
> that the same servlet would like to call it's own doPost()
> method.  How can it be done?

Just code the call in, I don't see what the problem is.  For example,
a doGet() can consist of nothing but a call to the doPost() (or
vice-versa).


> --- Manish Bhatnagar <[EMAIL PROTECTED]> wrote:
> > Hi Manisha,
> >
> > The simple way out to this problem is to call doPost() from
> > doGet() method.  When you call a servlet from a servlet... the
> > doGet() method of the invoved servlet is called... so your
> > doPost() method is invoked. I hope that answers to your question.
> >
> >
> > Manisha Menon wrote:
> >
> > > Hi all,
> > >
> > > Can someone tell me how to invoke doPost() method of a servlet
> > > from another servlet?  I think by forwarding using
> > > RequestDispatcher, you can only call doGet() method, right?
> > > Please reply me how to call doGet() directly.
> > >
> >
>

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to