Unknown

Servlet API

Servlet API

Servlet API consists of two important packages that encapsulates all the important classes and interface, namely :
  • javax.servlet
  • javax.servlet.http

Some Important Classes and Interfaces of javax.servlet

INTERFACESCLASSES
ServletServletInputStream
ServletContextServletOutputStream
ServletConfigServletRequestWrapper
ServletRequestServletResponseWrapper
ServletResponseServletRequestEvent
ServletContextListenerServletContextEvent
RequestDispatcherServletRequestAttributeEvent
SingleThreadModelServletContextAttributeEvent
FilterServletException
FilterConfigUnavailableException
FilterChainGenericServlet
ServletRequestListener

Some Important Classes and Interface of javax.servlet.http

CLASSES and INTERFACES
HttpServletHttpServletRequest
HttpServletResponseHttpSessionAttributeListener
HttpSessionHttpSessionListener
CookieHttpSessionEvent

Servlet Interface

Servlet Interface provides five methods. Out of these five methods, three methods are Servlet life cycle methods and rest two are non life cycle methods.
Servlet interface example

GenericServlet Class

GenericServlet is an abstract class that provides implementation of most of the basic servlet methods. This is a very important class.
Methods of GenericServlet class
  • public void init(ServletConfig)
  • public abstract void service(ServletRequest request,ServletResposne response)
  • public void destroy()
  • public ServletConfig getServletConfig()
  • public String getServletInfo()
  • public ServletContext getServletContext()
  • public String getInitParameter(String name)
  • public Enumeration getInitParameterNames()
  • public String getServletName()
  • public void log(String msg)
  • public void log(String msg, Throwable t)

HttpServlet class

HttpServlet is also an abstract class. This class gives implementation of various service() methods of Servlet interface.
To create a servlet, we should create a class that extends HttpServlet abstract class. The Servlet class that we will create, must not override service() method. Our servlet class will override only the doGet() and/or doPost() methods.
The service() method of HttpServlet class listens to the Http methods (GET, POST etc) from request stream and invokes doGet() or doPost() methods based on Http Method type.
Httpservlet Api and creating first Servlet Class