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

, , No Comments

 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 −

  • getParameter( ) − You call request.getParameter( ) method to get the value of a form parameter.
  • getParameterValues( ) − Call this method if the parameter appears more than once and returns multiple values, for example checkbox.
  • getParameterNames( ) − Call this method if you want a complete list of all parameters in the current request.

0 टिप्पणियाँ:

Post a Comment