Servlet API consists two important packages that contains many in-built classes and interface, like:
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 |
INTERFACES | CLASSES |
---|---|
HttpServlet | HttpServletRequest |
HttpServletResponse | HttpSessionAttributeListener |
HttpSession | HttpSessionListener |
Cookie | HttpSessionEvent |
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.
1,2,3 are servlet life cycle methods and 4,5 non life cycle methods.
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 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.
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