GET and POST

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • santoshmiracle
    New Member
    • Jul 2007
    • 12

    GET and POST

    how can we make a servlet to handle both GET and POST requests from html,is it possible?
  • sumittyagi
    Recognized Expert New Member
    • Mar 2007
    • 202

    #2
    Originally posted by santoshmiracle
    how can we make a servlet to handle both GET and POST requests from html,is it possible?
    simply make a function, and call that from both doGet and doPost of the servlet.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by santoshmiracle
      how can we make a servlet to handle both GET and POST requests from html,is it possible?
      Yes it is possible; quite a few Servlets simply make the method that handles
      the POST delegate to the method that handles the GET.

      kind regards,

      Jos

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by sumittyagi
        simply make a function, and call that from both doGet and doPost of the servlet.
        There's also the service method for that kind of thing.

        Comment

        • sumittyagi
          Recognized Expert New Member
          • Mar 2007
          • 202

          #5
          Originally posted by r035198x
          There's also the service method for that kind of thing.
          But doGet and doPost methods extends service method and do all the preliminary tasks for HTTP GET and POST request, so calling them is a better approach.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by sumittyagi
            But doGet and doPost methods extends service method and do all the preliminary tasks for HTTP GET and POST request, so calling them is a better approach.
            I don't get what you mean by method extends another method. But I get the point that we are talking about HttpServlet here so overring the service method is not required and should not be done. The service method for HttpServlet knows which one to call between the doGet and doPost. To make them do the same thing then your method of making a separate method and calling it from both is probably best.

            Comment

            • sumittyagi
              Recognized Expert New Member
              • Mar 2007
              • 202

              #7
              Originally posted by r035198x
              I don't get what you mean by method extends another method. But I get the point that we are talking about HttpServlet here so overring the service method is not required and should not be done. The service method for HttpServlet knows which one to call between the doGet and doPost. To make them do the same thing then your method of making a separate method and calling it from both is probably best.
              Yea, you are right, I got lost, what I said about doGet and doPost is applicable for service method. I mean service method overrides generic service method, and do all the preliminary things about an HTTP request and calls the appropriate doXXX method. So we should not override service method, else we would have to do all the preliminary work ourselves.

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by sumittyagi
                Yea, you are right, I got lost, what I said about doGet and doPost is applicable for service method. I mean service method overrides generic service method, and do all the preliminary things about an HTTP request and calls the appropriate doXXX method. So we should not override service method, else we would have to do all the preliminary work ourselves.
                Or just insert a call to super.service()

                Comment

                • sumittyagi
                  Recognized Expert New Member
                  • Mar 2007
                  • 202

                  #9
                  Originally posted by r035198x
                  Or just insert a call to super.service()
                  Yea, very true! (I forgot that option).

                  Comment

                  Working...