Pr.Pg Next Pg

Architecture of Servlet tutorials

  • The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or, more commonly, by extending a class that implements it such as HttpServlet. The inheritance hierarchy looks as follows.


inheritance hierarchy of servlets

  • The two main classes are the GenericServlet and HttpServlet classes.

  • The HttpServlet class is extended from GenericServlet. When you are developing your own servlets, you will most likely be extending one of these two classes.

  • Java servlets do not have a main() method, which is why all servlets must implement the javax.servlet.Servlet interface.

  • Every time a server receives a request that points to a servlet it calls that servletís service() method.

  • If you decide to extend the GenericServlet class, you must implement the service() method. The GenericServlet.service() method has been defined as an abstract method to force you to follow this framework.

  • The Servlet interface provides the following methods that manage the servlet and its communications with clients.

  • destroy(): Cleans up whatever resources are being held and makes sure that any persistent state is synchronized with the servlet's current in-memory state.

  • getServletConfig(): Returns a servlet config object, which contains any initialization parameters and startup configuration for this servlet.

  • getServletInfo(): Returns a string containing information about the servlet, such as its author, version, and copyright.

  • init(ServletConfig): Initializes the servlet. Run once before any requests can be serviced.

  • service(ServletRequest, ServletResponse): Carries out a single request from the client.

Pr.Pg border                                              Next Pg