Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Why doGet() method inside a doPost() method?

  Asked By: Bailey    Date: Mar 21    Category: Java    Views: 14978

Do you know what is the use to have a doGet() method
inside a doPost() method in servlet like the

public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException,IOException



6 Answers Found

Answer #1    Answered By: Oscar Evans     Answered On: Mar 21

Get and Post differ in the way server treats them and you can easily do
the same thing get does in post as long as you don't care. This servlet
responds similar to both post and get requests.

Answer #2    Answered By: Michael Evans     Answered On: Mar 21

We use doGet() method  inside the doPost() method to go from DoPost method to DoGet method.

Answer #3    Answered By: Woodrow Jones     Answered On: Mar 21

doGet() and doPost() are called in different
ocassions, when you call an URL you normally make a
GET request, when you put a form and set the <FORM
METHOD=POST> then you have a post request. Forms can
be either get or post, so to process a form request
yuou may program both methods or you mey loose some
so, the easieste way is to call doPost() from doGet()
or viceversa or point both of them to your function.

Answer #4    Answered By: Iris Sanders     Answered On: Mar 21

you'd better override these two methods separately . but if you use nested forms or some several frames with separate forms(maybe each form has its own method), in your HTML tags you may need to impelemnting doGet() within doPost() method  .

Answer #5    Answered By: Olga Allen     Answered On: Mar 21

This is the proposed default implementation in servlet  specification.
If for some reasons you need to handle these methods separately you
can override them.

Answer #6    Answered By: Nanda Sivaraju     Answered On: Jun 15

This line of code is auto created by the IDE when we create the servlet class. This is because the IDE does not know exactly what you want to do with the doPost() method but it tries to hand over the servlet in a consistent state by calling doGet() method. In this way if you click submit whithout implementing doPost() it makes sure that we will be taken to the same page ,instead of crashing or seeing some exception.

Didn't find what you were looking for? Find more on Why doGet() method inside a doPost() method? Or get search suggestion and latest updates.