aspose file tools*
The moose likes Servlets and the fly likes doubts on service, post, get metods? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "doubts on service, post, get metods?" Watch "doubts on service, post, get metods?" New topic
Author

doubts on service, post, get metods?

Sashidhar Rao Gopisetty
Greenhorn

Joined: Sep 23, 2005
Posts: 19
hi Keith Pitty
u said service method is not designed to be overridden but it means it can be done is'ntit?
if i dont have service method at all then how container in vokes servlet?
is service method is manditory?
can we have post and get both?
can we override the post wit get r vice versa?
is any one methos is enough?


�Don't limit your challenges - challenge your limits.�<br /> <br />Thanks & Regards<br />GDS Sashidhar Rao
Keith Pitty
Ranch Hand

Joined: Sep 22, 2005
Posts: 32
Sashidhar,

The container responds to an HTTP request that is either a GET or POST request, depending on how it was invoked (e.g. a GET request from an HTML hyperlink).

The container then passes the request to the service method (not overridden) of the servlet. Then the service method delegates to either the doGet or doPost. Both these methods should usually be overridden so that the servlet can handle both types of requests.

Overriding implies that the method signature (i.e. name and arguments) is the same so to think of "overriding post with get" doesn't make sense.

I hope this helps. By the way have you had a look at the servlet API doc?
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334

hi Keith Pitty
u said service method is not designed to be overridden but it means it can be done is'ntit?
if i dont have service method at all then how container in vokes servlet?
is service method is manditory?
can we have post and get both?
can we override the post wit get r vice versa?
is any one methos is enough?



Usually service method of the servlet will be invoked by the container automatically and this method will invoke either doGet or doPost. On the other hand, if you override the service method in your servlet code, you have to explicitly identify which method you are going to handle. The container does not take the responsibility for invoking the corresponding method.
Service method is mandatory. Even if you dont override it manually, It will be invoked automatically by the container.
Yes. You can use both doGet & doPost in your servlet code.
Either you can use only doGet or doPost to handle the request.



I hope it will help you
bye for now
with luv
sat
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

if i dont have service method at all then how container in vokes servlet?


If you extend HttpServlet, then you have all the methods it implements:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServlet.html

Which ones you choose to override is up to you.
The default behaviour of the service method is to determine what type of
request this is and delegate to the proper method (toPost, doGet, doHead, etc..).
There is generally no good reason to override it.

The default behaviour of both doGet and doPost is to throw an exception letting the user (or container) know that this method is not implemented.
If you want your servlet to do more than that for either of these request
types, you should override them.

If you want your servlet to handle POST and GET requests with the same
code (the way a JSP does), simple call one method from the other.



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubts on service, post, get metods?
 
Similar Threads
please reply urgently!!!
code written in scriptlet of JSP
regarding servlet service method
service() in HttpServlet
Problem with doGet and doPost methods