Results 1 to 2 of 2

Thread: doget method instead of doPost

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Answers
    2

    doget method instead of doPost

    Suppose I am calling doPost method from the html but there is no such method defined in servlet in place of doPost method we define doget method then what will happen?


  2. #2
    Junior Member
    Join Date
    Jul 2007
    Answers
    4

    Post Re: doget method instead of doPost

    well..a good question i would say and i was asked the same thing in one of my JAVA tech interviews..and I answered it

    If you implement only doGET() and dont implement doPOST() then all the POST requests for such a servlet are rejected by the servlet container giving error back to the client which (might) say 405 Resource not found.

    Later on, I tested the same with resin web container and found that i was right.
    I guess the error messages might differ from one web container to another, but the end result i.e. request rejection will always happen as mentioned above.

    Following excerpt from resin webpage says:
    Error 405 resource not found

    Usually, this is a servlet extending HttpServlet and implementing doGet but not doPost. If you send a POST request, like a form, to a servlet that only implements doGet, you will get 405 resource not found.

    Also this http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=7&t=019923 says:

    "the doXXX methods are called by service() method which in turn is called by the container (tomcat for example) , the service() mehtod will always be called when ever a request comes to the container for a resource(servlet) but by allowing you to implement the doXXX() methods , the container gives you the power to accept or reject particular types of requets , for example if you implement only doGET then the Post requests will not be processed and vice versa."

    Hope this helps!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact