GeeCON Prague 2014*
The moose likes Servlets and the fly likes calling doPost() from doGet() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "calling doPost() from doGet()" Watch "calling doPost() from doGet()" New topic
Author

calling doPost() from doGet()

ashok alapati
Greenhorn

Joined: Oct 05, 2006
Posts: 1
To call doPost() from doGet do we need to cheak any condition ?.If yes what is that condition?.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I don't think you need any condition.


[My Blog]
All roads lead to JavaRanch
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
I feel the same. But you have to remember that GET has upper cape on parameters size � so just you may like to apply checks related if you are sending really long strings or too many parameters. Otherwise in normal situation, I don�t feel to have any checks.
[ October 06, 2006: Message edited by: Chetan Parekh ]

My blood is tested +ve for Java.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
In case you are calling a doGet from a doPost , doGet behaves like any other normal java method.Actually those are callback methods which the service method is suppose to call after determining the HTTP method from the request.


Rahul Bhattacharjee
LinkedIn - Blog
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
In case you want similar behaviour for both GET and POST requests then you might even choose to override the service method itself.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Rahul Bhattacharjee:
In case you want similar behaviour for both GET and POST requests then you might even choose to override the service method itself.


GET and POST are not the only HTTP methods that exist. Overriding service() would kill the distinction between these and the other methods, like HEAD. If all one is trying to do is make the behaviour for GET and POST the same, then the best way is to make doGet call doPost (or maybe vice versa).


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Just remember that there are very different reasons as to why someone might be calling a doGet, as opposed to a doPost.

If your servlet should only be called from a form, and doPost handles this, then you need to know why the doGet has been called. Has someone just clicked on a bookmark? Has someone typed the URL in, instead of clicking submit on the form? Has the page simply been refreshed after the session has timed out?

State management in a Servlet is always a tricky issue. Simply calling doPost from doGet might mean you're avoiding a variety of state management issues.

I know that the VisualAge for Java and eariler editions of WebSphere Studio actually had a third method that each post/get/head method would call. That way you could handle management issues in the appropriate get/post method, and then perform the web based control logic in the third method. Of course, having said that, I've noticed that have stopped doing that in IBM's Raional Application Developer (IRAD)

But otherwise, just calling doPost from doGet is fine.

-Cameron McKenzie
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Originally posted by Kameron McKenzie:
If your servlet should only be called from a form, and doPost handles this, then you need to know why the doGet has been called. Has someone just clicked on a bookmark? Has someone typed the URL in, instead of clicking submit on the form? Has the page simply been refreshed after the session has timed out?


Kameron McKenzie, you got the point here!
 
GeeCON Prague 2014
 
subject: calling doPost() from doGet()