by Dinesh Thakur

Like doGet () method, the do Post () method is invoked by server through service () method to handle HTTP POST request. The doPost () method is used when large amount of data is required to be passed to the server which is not possible with the help of doGet () method.

 
by Dinesh Thakur

The doGet () method is invoked by server through service () method to handle a HTTP GET request. This method also handles HTTP HEAD request automatically as HEAD request is nothing but a GET request having no body in the code for response and only includes request header fields. To understand the working of doGet () method, let us consider a sample program to define a servlet for handling the HTTP GET request.



 
by Dinesh Thakur

The GenericServlet class implements the Servlet and ServletConfig interfaces. Since service () method is declared as an abstract method in GenericServlet class, it is an abstract class. The class extending this class must implement the service () method. It is used to create servlets which are protocol independent.



 
by Dinesh Thakur

The process of selecting file from the client machine file system and sending that file to the server machine system is known as file uploading. File uploading and downloading using servlet-api is a complex process, that is why industry uses JavaZoom 3rd party API.

 
by Dinesh Thakur

HttpServletResponse is a predefined interface present in javax.servlet.http package. It can be said that it is a mirror image of request object. The response object is where the servlet can write information about the data it will send back. Whereas the majority of the methods in the request object start with GET, indicating that they get a value, many of the important methods in the response object start with SET, indicating that they change some property. Note that these interfaces adhere to the usual naming conventions for beans.



 
by Dinesh Thakur

HttpServletRequest is an interface and extends the ServletRequest interface. By extending the ServletRequest this interface is able to allow request information for HTTP Servlets. Object of the HttpServletRequest is created by the Servlet container and, then, it is passed to the service method (doGet(), doPost(), etc.) of the Servlet.



 
by Dinesh Thakur

Before handling HTTP get requests and HTTP post requests, you should have some knowledge about HTML forms.

 
by Dinesh Thakur

By default every web resource program generated output/response content will be stored in the buffer before it is getting displayed on browser window as web page content. Due to this browser window may show old output collected from the buffer even though the web resource program of web application is capable of generating new and updated output.   

 
by Dinesh Thakur

We can gather the miscellaneous information from HttpRequest by calling various getxxx methods on request object as shown below.

* Use user-agent request header that holds browser software name as shown below.



 
by Dinesh Thakur

No, Because Servlet container uses 0-param constructor of our Servlet class that create the object of our Servlet class. If 0-param constructor (default constructor) not available then the Servlet container throws: java.lang.InstantiationException.



 
by Dinesh Thakur

Once the Tomcat is installed and configured, you need to perform the following steps to create and run a servlet.