Monday, June 25, 2018

HTTP Servlet Methods


  • doGet()
  • doPost()
  • doHead()
  • doPut()
  • doDelete()
  • doOptions()
  • doTrace()
Get Method:
  • The GET method sends the encoded user information appended to the page request in the URL.
  • The page and the encoded information are separated by the ? character as follows:
                        http://www.test.com/hello?key1=value1&key2=value2
  • The GET method has size limtation: only 1024 characters can be in a request string.  
       Signature of the doGet() method:
            public void doGet(HttpServletRequest request, HttpServletResponse 
                  response) throws ServletException, IOException {
                           // Servlet code
            }

Note: Never use get method to pass password or other sensitive information.

Post Method:
  • More reliable method of passing information is the POST method.
  • Post method also packages the information exactly the same way as GET methods, but instead of sending it in the URL, it sends it as a separate message.
  • There is no limitation for the Post method.
       Signature of the doPost() method:
           public void doPost(HttpServletRequest request, HttpServletResponse response)    
                throws ServletException, IOException {
                        // Servlet code
           }


No comments:

Post a Comment