Monday 22 July 2013

What is the difference between GET and POST method in java?


Get and Post are both the method of HTML form element and they are used to transfer data with the request when the submit button is pressed as:
 

<form action="firstServlet" method="get">     

         <table>

            <tr> <td>

                 <input type="Text" name="UsrName"/>

            </td> </tr>

            <tr><td>

                 <input type="Text" name="pswd"/>

           </td> </tr>

            <tr><td>

                 <input type="submit" name="submit" value="Submit"/>

           </td></tr>

        </table>

</form>

In the above code we have two text box’s  user name and password and one submit button, When we click on the submit button after putting values in the user name and password boxes the control will transfer to the “firstServlet” servlet with the user name and password entered.

The main differences between GET and POST method are as follow.

 

GET

POST

Get request contents are visible in URL

Post request contents are embedded in the body of HTTP request

Get method can only contain data up to 255k

NO such limit for post method

Get request can be cached

Post request contents are not a part of URL so they cannot be cached

Get requests are usually faster than post requests

They are slower than get because they need some extra time to encapsulate in the body of request

Get is a by default method of HTML form element

Post method need be specified for use

Get request can only contain the text data

Post can contain text as well as binary data

 

No comments:

Post a Comment