What is Servlet? Explain GET and POST methods of Servlet.

QuestionsWhat is Servlet? Explain GET and POST methods of Servlet.
manish.mishraPublished on: 6/21/2021 1:46:23 PM



1 Answers
Answer is under review.

Servlet can be described in many ways, depending on the context.

  • Servlet is a technology which is used to create a web application.
  • Servlet is an API that provides many interfaces and classes including documentation.
  • Servlet is an interface that must be implemented for creating any Servlet.
  • Servlet is a class that extends the capabilities of the servers and responds to the incoming requests. It can respond to any requests.
  • Servlet is a web component that is deployed on the server to create a dynamic web page.


GET Method

The GET method is the default method to pass information from browser to web server and it produces a long string that appears in your browser's Location box. Never use the GET method if you have password or other sensitive information to pass to the server. The GET method has size limitation : only 1024 characters can be used in a request string.

This information is passed using QUERY_STRING header and will be accessible through QUERY_STRING environment variable and Servlet handles this type of requests using doGet( ) method.

POST Method

A generally more reliable method of passing information to a backend program is the POST method. This packages the information in exactly the same way as GET method, but instead of sending it as a text string after a ? (question mark) in the URL it sends it as a separate message. This message comes to the backend program in the form of the standard input which you can parse and use for your processing. Servlet handles this type of requests using doPost( ) method.

Servlets handles form data parsing automatically using the following methods depending on the situation −


getParameterNames( ) − Call this method if you want a complete list of all parameters in the current request.

getParameterValues( ) − Call this method if the parameter appears more than once and returns multiple values, for example checkbox.

getParameter( ) − You call request.getParameter( ) method to get the value of a form parameter.