This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have basic question in servlet. when to use doGet and doPost methods and in some examples i have seen that in doPost method, just doGet method is called and vice versa. I know that when we go for doGet we could see the data which we send in the url and there is limit in it.can any one please explain me in brief about this.Thanks in advance
doPost() and doGet() get called by the application server when a client accesses the servlet with POST and GET methods, respectively.
IN GENERAL, GET and POST requests fulfill the same basic requirement, which is the submission of form data. That's why many servlets just have one of these methods do any real processing while the second one just forwards all requests to the first.
What are the advantages of the two HTTP requests? - You can simulate the submission of an HTML form that uses GET by typing the form information in on the browser's addess line. - A form that uses a POST method can include more data because it's not limited to the max length of a URL.
Is it possible to have two completely different implementation for doGet() and doPost()? Yes. You might require relatively sensitive information to be submitted with a POST so that the data isn't stored in the browsers URL history. In that case you'd implement doPost() but perhaps have doGet() return an error page.
1. Acessing a web site by clicking a link or typing the address in the browser address field will almost always cause your browser to use GET.
2. Some browsers cannot handle query strings longer than 255 bytes unless you use POST.
3. You cannot upload binary data, such as a jar file containing bytecode, with GET.
4. Your URL cache (the drop-down box under the address field) and your bookmarks save the query string with the URL. This lets you save a particular inquiry, logon, etc., to a web site but it only works with GET.
5. You cannot use POST to directly access an html document.
The designers of HTTP intended the commands to have meaning. GET should retrieve a resource (page, document, image, etc) and not change state. POST should submit an update. PUT should put a resource. DELETE should delete it. If you want to dig deep into this, see Fielding's dissertation which defines "rest" architecture. Also google for "rest vs soap" or "rest vs rpc" for some interesting discussions.
I'm a fan of POST-Redirect-GET when doing updates. The POST updates the resource and redirects the browser to the page to GET the resource.
If a resource is available via GET then users can bookmark it, send the link to their friends or hit the refresh button without that annoying popup that says the browser must re-send request data to get the page.
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