aspose file tools*
The moose likes Servlets and the fly likes when to use get method versus post method in the servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "when to use get method versus post method in the servlet?" Watch "when to use get method versus post method in the servlet?" New topic
Author

when to use get method versus post method in the servlet?

BalaMurali dhar
Ranch Hand

Joined: Apr 14, 2012
Posts: 60
when we use Get method & when we use get post method in the Servlet?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

To put it briefly, you use the POST method when your request is meant to change the state of the server. That would include updating databases, adding to shopping carts, and things like that. You use the GET method when your request is not meant to change the server's state; that would include requests for information from the server.

There are grey areas and complexities which I haven't mentioned, as there always are in questions of this type, but that's the general idea.

For example if my request is supposed to make a dentist appointment for me next Tuesday at 11 AM, that would be a POST request because that information is going to be stored at the server. However if my request is supposed to find out what times are available for appointments on Thursday, that would be a GET request.

caushik conjetty sekhar
Greenhorn

Joined: Mar 03, 2009
Posts: 4
We use POST method when we want to submit the data to the server, For example if you are submitting the details of an employee. Use GET method when you want to bookmark your page or retrieve simple data. GET is not secure since the data is appended in the URL, in POST data is sent in the body so the data is not seen to outside world.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

caushik conjetty sekhar wrote:Use GET method when you want to bookmark your page or retrieve simple data.

Complexity of the data is irrelevant. The GET method should be used to get data regardless of whether it is complex or simple.

GET is not secure since the data is appended in the URL, in POST data is sent in the body so the data is not seen to outside world.

This is a popular myth, and is completely wrong.

Just because POST data is in the body of the request it is no more secure than data placed on the URL. All unencrypted data sent over the Internet is visible to anybody along the way.

POST is in no way more secure than GET, and GET is no less secure than POST. If you want to protect the data, use SSL to encrypt the transmitted data.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
RajeshKumar Nayak
Greenhorn

Joined: Jul 02, 2012
Posts: 6
fist Declare post method
inside the post method you declare
doGet(request, response);
thats all
....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

RajeshKumar Nayak wrote:fist Declare post method
inside the post method you declare
doGet(request, response);
thats all

No, that's not all. You cannot declare one method inside another. What on Earth are you talking about?

Even so, another myth is that EGT and POST are interchangeable. They are not as described above. Each is used for different purposes.
 
 
subject: when to use get method versus post method in the servlet?