Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling doPost() from doGet()

 
ashok alapati
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To call doPost() from doGet do we need to cheak any condition ?.If yes what is that condition?.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you need any condition.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic