Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Concept of using doGet and doPost together

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
Ranch Hand
Posts: 462
Scala jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Oprah Thaddeus
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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" ?
 
Oprah Thaddeus
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
    Bookmark Topic Watch Topic
  • New Topic