aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Concept of using doGet and doPost together Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Concept of using doGet and doPost together" Watch "Concept of using doGet and doPost together" New topic
Author

Concept of using doGet and doPost together

Brijesh shah
Ranch Hand

Joined: Mar 16, 2007
Posts: 90
Dear Friends;

In general by referring different types of servlet examples , I have found that in some examples they have used doGet and doPost method together in the code.. I want to know logic behind it.

I do not understand the concept of using doGet and doPost methods together in the Servlet..I want to know, Why and when we would need to use both methods together in the servlet code.

Thanking you.

--
Brijesh

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I want to know logic behind it.

The doGet method is called when a GET request is sent, and the doPost when a POST request is sent. So if you want to support both GET and POST, you'll have to override both doGet and doPost methods.


[My Blog]
All roads lead to JavaRanch
piyush maheshwari
Greenhorn

Joined: Aug 24, 2009
Posts: 4
Yes I do know that to take advantage of both HTTP GET and HTTP POST methods we override
both doGet() and doPost(). But one question who decides which one to use when request is sent by client- GET or POST
Brij Garg
Ranch Hand

Joined: Apr 29, 2008
Posts: 234

But one question who decides which one to use when request is sent by client- GET or POST


It is the container which decides which method (doGet or doPost) to call from service method depending upon the HTTP method.

Let me know in case I need some correction.
Will Myers
Ranch Hand

Joined: Aug 05, 2009
Posts: 313

The default is to use GET unless you specify otherwise in the request by including something like <form name="localeForm" action="index.jsp" method="POST"> in the JSP
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
Please correct me if I am wrong.

It is the HTML form that says whether it will be get (default) or post. Period.! Am I right?


Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

It is the HTML form that says whether it will be get (default) or post. Period.! Am I right?

Not only. For example, accessing a page via the browser's url address bar, will send a GET request.
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
Christophe Verré wrote:
It is the HTML form that says whether it will be get (default) or post. Period.! Am I right?

Not only. For example, accessing a page via the browser's url address bar, will send a GET request.

Do you not access pages though client's (browser's) address bar? And, the client runs either some sort of form or jsp?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Do you not access pages though client's (browser's) address bar? And, the client runs either some sort of form or jsp?

Not necessarily. The url can be mapped to a servlet. Have you never seen url looking like "/register.do" ?
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
Christophe Verré wrote:
Do you not access pages though client's (browser's) address bar? And, the client runs either some sort of form or jsp?

Not necessarily. The url can be mapped to a servlet. Have you never seen url looking like "/register.do" ?


as in servlet mapping of DD? umm... I am new in SCWCD.. And trying hard to realize all the concepts.. Can you elaborate bit more. Thanks in advance

By the way, in the DD we are only doing mapping... Hence, I am not sure if we can let the app know if it will be get or post in the DD? Can we ? I thought the only options is in the html form. If it explictly states that it is post, then it is. Else it is get by deafault. I am getting more and more confused as I go deeper in SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Concept of using doGet and doPost together
 
Similar Threads
Doubts in service()/doPost()/doGet()
doPost and doGet
I'm completely new to JSP's how does it compare to...
servlets
GET method working but POST method not working