Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using get() and post() together

 
Manas Ahlaad
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i use get() and post() together so that the mechanism results in using get() for idempotent requests and post() for nonidempotent requests??
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know you can have doGet() call doPost() and vice-versa. Not sure what you mean by indempotent and nonidempotent requests.
 
arif azim
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The GET operation is also expected to be idempotent, meaning that it can safely be repeated. This is not quite the same as being safe, but in some common examples the requirements have the same result. For example, repeating queries is both safe and idempotent (unless payment is required!), but buying something or modifying data is neither safe nor idempotent.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya, u can use doGet and doPost() methods together.
The service method calls the appropriate method based when the request method was get or post.
 
Manas Ahlaad
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how does doget() call dopost() ??
what is the advantage of that??
 
Dorothy Finkel-Laverty
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I teach Java in a technical post-secondary school. We use a doPost that calls a doGet mostly for teaching purposes - that way, the students can use doGet and therefore, see the name/value pairs being passed to the server, and then, when they are ready for "production release", simply change their method to post. The doPost has one line of code in it - which calls the doGet and passes the appropriate request & response objects. Seeing the name/value pairs makes it easier for the beginning students to see what their program bugs might be.
I recommend it to them as a development tool, but tell them that they would normally change it to a post before installing the program.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I love University students, they use big words.

http://www.dictionary.com/search?q=idempotent
 
Zkr Ryz
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by manas ahlaad:
how does doget() call dopost() ??
what is the advantage of that??

public void doGet( HttpServletRequest request,
HttpServletResponse response )
{
doPost( request, response );
}
 
Val Pecaoco
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I use Forte in my projects and here's a skeleton servlet code that Forte generates when you create a new servlet:

I guess you notice that the method processRequest() is being called by both doGet() and doPost().
Ex Animo Java!
-- Val
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic