We can implement servlet programming by using the following two packages


  • javax.servlet:This package is used to develop servlets from scratch irrespective of any protocol
  • javax.servlet.http:This package is used to develop http based servlets.

javax.servlet package



  1. Servlet interface

    • Every servlet in JAVA should compulsory implement Servlet interface either directly or indirectly
    • This interface defines the most common methods which can be applicable on any servlet Object
    • This interface defines life-cycle methods of servlet
  2. ServletReuqest

    • Servlet Request object can be used to hold client information
    • This interface defines several methods to retrieve the client information
  3. ServletResponse

    • Response object can be used to send response to the client.
    • This interface defines several methods which can be used for preparation of response.
  4. ServletConfig

    • For every servlet web container creates one ServletConfig object to hold servlet information.
    • Web container provides this object to servlet as argument to init() method.
    • Servlet can get it’s configuration information by this config object.
  5. ServletContext

    • For every web application web container creates ServletContext object to hold application level information

    Note:ServletConfig is for servlet, where as ServletContext is for web application.

  6. RequestDispatcher

    • We can use request dispatcher for dispatching request to other web component.
    • it contains the following two methods
      • include()
      • forward()
  7. SingleThreadModel

    • tThis is for providing thread safety to the servlet.
    • Servlet has to implement this interface to guarantee that it can handle only one client request at a time.
    • Implementing SingleThreadModel effects performance, hence sun people deprecated this interface in servlet2.3 version without any replacement.
    • singleThreadModel doesn’t contain any method it a marker interface.

    In addition to the above interfaces javax.servlet package contains the following interfaces also

    1. Filter
    2. FilterConfig
    3. FilterChain
    4. for implementing Filters

    5. ServletRequestListener
    6. ServletRequestAttributeListener
    7. ServletContextListener
    8. ServletContextAttributeListener
    9. for implementing listeners concept



    • This class implement Servlet interface
    • We have to use this class to develop protocol independent servlets.


    • we can use this object to send binary information as response.


    • By using this object we can read binary information sent by the end user

    In addition to the above classes javax.servlet package contains the following classes also

    1. ServletRequestWrapper
    2. ServletResponseWrapper

    for implementing wrapper concept.

    1. ServletRequestEvent
    2. ServletRequestAttributeEvent
    3. ServletContextEvent
    4. ServletContextAttributeEvent

    for defining events in listeners


    1. ServletException

    2. It defines a general exception that servlet can throw when ever it faces some difficulty while processing the request.

    3. UnavailableException

    4. It is child class of ServletException and it is deprecated