Servlet API

Servlet API consists two important packages that contains many in-built classes and interface, like:

  • • javax.servlet
  • • javax.servlet.http

Some In-built Classes and Interfaces of javax.servlet

INTERFACES CLASSES
Servlet ServletInputStream
ServletContext ServletOutputStream
ServletConfig ServletRequestWrapper
ServletRequest ServletResponseWrapper
ServletResponse ServletRequestEvent
ServletContextListener ServletContextEvent
RequestDispatcher ServletRequestAttributeEvent
SingleThreadModel ServletContextAttributeEvent
Filter ServletException
FilterConfig UnavailableException
FilterChain GenericServlet
ServletRequestListener

Some Important Classes and Interface of javax.servlet.http

INTERFACES CLASSES
HttpServlet HttpServletRequest
HttpServletResponse HttpSessionAttributeListener
HttpSession HttpSessionListener
Cookie HttpSessionEvent

Servlet Interface

Servlet Interface provides five methods. Out of these five methods, three methods are Servlet life cycle methods and remaining two methods are apart from life cycle methods.

  • • public void init(ServletConfig config) throws ServletException
  • • public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
  • • public void destroy()
  • • public abstract ServletConfig getServletConfig()
  • • public abstract String getServletInfo()

1,2,3 are servlet life cycle methods and 4,5 non life cycle methods.


GenericServlet Class

GenericServlet is an abstract class that provides implementation of most of the basic servlet methods. 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.


About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext