File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Using get() and post() together Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Using get() and post() together" Watch "Using get() and post() together" New topic

Using get() and post() together

Manas Ahlaad
Ranch Hand

Joined: Nov 07, 2001
Posts: 165
can i use get() and post() together so that the mechanism results in using get() for idempotent requests and post() for nonidempotent requests??

Manas<br />Today If You are not Confused,You are just not thinking Clearly !<br />---------------------------------
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I know you can have doGet() call doPost() and vice-versa. Not sure what you mean by indempotent and nonidempotent requests.

So much trouble in the world -- Bob Marley
arif azim

Joined: Mar 26, 2002
Posts: 7
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

Joined: Feb 27, 2002
Posts: 8927

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

Joined: Nov 07, 2001
Posts: 165
how does doget() call dopost() ??
what is the advantage of that??
Dorothy Finkel-Laverty
Ranch Hand

Joined: Nov 24, 2001
Posts: 51
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

Joined: Feb 20, 2001
Posts: 3695

I love University students, they use big words.
Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
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

Joined: Dec 05, 2001
Posts: 156
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

"Knowledge is power, but enthusiasm is the key." -- Lavern Barn
I agree. Here's the link:
subject: Using get() and post() together
It's not a secret anymore!