Servlet API
Servlet API consist of two important packages that encapsulate all the important
classes and interface.
1)javax.servlet
2)javax.servlet.http
Some Important Classes and Interface of javax.servlet
CLASSES | INTERFACES |
Servlet | ServletRequest |
ServletResponse | ServletConfig |
ServletContext | RequestDispatcher |
FilterChain | Filter |
ServletInputStream | GenericServlet |
ServletOutputStream | ServletException |
Some Important Classes and Interface of javax.servlet.http
CLASSES |
and INTERFACES |
HttpServlet | HttpServletRequest |
HttpServletResponse | HttpSessionAttributeListener |
HttpSession | HttpSessionListener |
Cookie | HttpSessionEvent |
Servlet Interface:
Servlet Interface provides five method. Out of this five method three
method are servlet life cycle method and rest two are non life cycle
method.
servlet interface example
GenericServlet Class
GenericServlet is an abstract class that provide implementation of most of the
basic servlet method.
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 a abstract class. This class gives implementation of
service() method of Servlet interface.
To create a servlet, we should create a class that extends HttpServlet
abstract class. The servlet class that we will create should not override
service() method. Our servlet class will override only doGet() and/or doPost()
method.
The service() method of HttpServlet class look at the Http method(GET,
POST etc) from request stream and invokes doGet() or doPost() method
based on Http method.