Collection of frequently asked interview questions from Servlet.
A Servlet can be created by extending the httpServlet or GenericServlet classes.
Servlets are server side components that provide a powerful mechanism for developing server side programs. Servlets provide component-based, platform-independent methods for building Web-based applications, without the performance limitations of CGI programs.
Servlet interface contains three methods known as life-cycle methods.
Init , service and destroy.
First the servlet is constructed, then initialized with the init() method. Any request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet. The servlet is removed from service, destroyed with the destroy() method, then garbaged collected and finalized.
A GenericServlet has a service() method to handle the requests. HttpServlet extends GenericServlet and adds support for doGet (), doPost () methods doPut (), doOptions (), doDelete (), doTrace () methods.
ServletContext: It defines a set of methods that a servlet uses to communicate with its container.
ServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet.
The session is an object used by a servlet to track a user’s interaction with a Web application across multiple HTTP requests. The session is stored on the server.