by Dinesh Thakur Category: Basic Servlet Examples

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 Category: Basic Servlet Examples

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 Category: Basic Servlet Examples

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 Category: Basic Servlet Examples

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 Category: Basic Servlet Examples

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 Category: Basic Servlet Examples

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

 
by Dinesh Thakur Category: Basic Servlet Examples

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 Category: Basic Servlet Examples

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



 
by Dinesh Thakur Category: Basic Servlet Examples

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 Category: Basic Servlet Examples

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.



 

Page 1 of 2



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.