what's the difference?


Web tier: servlets, JSP, Web frameworks: what's the difference?

  1. what's the difference? (1 messages)

    who can tell me what's the difference between doPost,doDelete,doTrace,doPut,service,doOption,and doGet method in servlet,thank you!

    Threaded Messages (1)

  2. what's the difference?[ Go to top ]

    the doXXX correspond to a browser request action. usually you would only use either doPost or doGet or both.

    doGet processes parameters in the URL

    i.e. http://localhost/test/load.jsp?param1=blah&param2=foo

    if you had a html form with method=get, then your target will have attribute value pairs appended to the url separated by ampersands.


    <form method="get" action="process.jsp">
    <input type="text" name="firstName" value="Joe">
    <input type="text" name="lastName" value="Yi">
    <input type="submit" name="submit" value="Submit">

    when the user hits submit, it goes to process.jsp, but the URL looks like this:


    In a method=post operation, you don't see the parameters in the URL.

    Also, if you have a servlet with only one or the either, and not both, than your servlet will only accept requests of that type.

    if my servlet has doGet, and then I can access it directly through the URL http://localhost/servlet/MyServlet

    if it ONLY has doPost, then my request will be rejected for http://localhost/servlet/MyServlet if I try to access it directly. a doPost requires a POST operation.

    service( ) is basically what gets called by the doXXX methods, so it is not really used directly. I've seen it used in older servlets tho.