Author | Topic: Differences Between doGet(),doPost(),service() |
ganapathy gopinathan greenhorn Member # 78471 | posted September 28, 2004 07:52 AM
Hi all,
Anyone plz help me to understand the differences between the doGet(),doPost(),and service() methods.
Thank u gopi
Posts: 30 | Registered: Aug 2004 | IP: Logged | |
sanjeevmehra mehra ranch hand Member # 79249 | posted September 28, 2004 08:09 AM
init() service() {goGet() & doPost()) destroy() are the lifecycle methods. init() & destroy() are called once in lifetime. And service() method is called whenever a request comes. If request is through the Get method, service() method calls (pass that request to) doGet() and if request is through post method service() method calls (pass that request to the) doPost() method.
thanks & regards, sanjeev.
Posts: 88 | Registered: Aug 2004 | IP: Logged -------------------- thanks & regards, Sanjeev. | |
Stan James (instanceof Sidekick) Member # 44095 | posted September 28, 2004 10:07 AM
Technically you can make doGet and doPost act identically. It's not uncommon to see both of those methods call doProcess or some other method you make up, allowing users to get or post at will.
The inventors of HTTP saw them as very different however. GET operations must be "idempotent" which just means they have no side effects and repeated calls should give the same result. A pure query in other words. POST operations should be used to send information to the server that will change the state of some object or data store.
HERE is an article on the topic that I happened to be reading right before I saw your note. The inventors of HTTP promote a web application architecture called REST (Representational State Transfer) that assigns very particular meaning to all the HTTP verbs - GET, POST, PUT, HEAD, etc - and further tells us that these are all we need.
Posts: 6763 | Registered: Jan 2003 | IP: Logged -------------------- A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi | |
|
|
|
|
|
Adeel Ansari ranch hand Member # 78839 | posted October 01, 2004 12:53 AM
hey gopi i found something simple and somewhat complete for you. here is that,
After the servlet is initialized, the container may keep it ready for handling client requests. When client requests arrive, they are delegated to the servlet through the service()method, passing the request and response objects as parameters. In the case of HTTP requests, the request and response objects are implementations of HttpServletRequest and HttpServletResponse respectively. In the HttpServlet class, the service() method invokes a different handler method for each type of HTTP request, doGet() method for GET requests, doPost() method for POST requests, and so on.
some more,
GET method The GET method is used to retrieve a resource (like an image or an HTML page) from the server, which is specified in the request URL. When the user types the request URL into the browser's location field or clicks on a hyperlink, the GET method is triggered. If a tag is used, the method attribute can be specified as "GET" to cause the browser to send a GET request. Even if no method attribute is specified, the browser uses the GET method by default. We can pass request parameters by having a query string appended to the request URL, which is a set of name-value pairs separated by an "&" character. Here we have passed the parameters studname and studno, which have the values "Tom" and "123" respectively. Because the data passed using the GET method is visible inside the URL, it is not advisable to send sensitive information in this manner. The other restrictions for the GET method are that it can pass only text data and not more than 255 characters (i read somewhere that it depends on browser support).
POST method The purpose of the POST method is to "post" or send information to the server. It is possible to send an unlimited amount of data as part of a POST request, and the type of data can be binary or text. This method is usually used for sending bulk data, such as uploading files or updating databases. The method attribute of the <form> tag can be specified as "POST" to cause the browser to send a POST request to the server. Because the request parameters are sent as part of the request body, it is not visible as part of the request URL, which was also the case with the GET method. [ October 01, 2004: Message edited by: adeel ansari ] -------------------- The code I wrote nine months ago sucks. And I'm happy about it. — Bear Bibeault
Posts: 2321 | Registered: Aug 2004 | IP: Logged | |
| |