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

Using get() and post() together

 
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??
 
Ranch Hand
Posts: 1512
  • 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.
 
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.
 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • 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??
 
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.
 
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
 
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 );
}
 
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
 
There is no "i" in denial. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic