If you are trying to create a servlet program of your own ,the two main class for servlet implementation are-
- GenericServlet---For all general purpose servlet capable of handling any protocol.
- HttpServlet-- HttpServlet is a extended class from GenericServlet , handles only HTTP protocol.
So when we try to create any of the servlet of our own ,we need to extend one of these classes.
P.S-Servlet does not contain any main() method instead it is having a service() method to work.
if you are extending GenericServlet:The two types of object a service method accepts are
public abstract void service(ServletRequest req,ServletResponse res) throws ServletException,IOException;
- Request--the information directing to the servlet
- Response--The information towards server viz client
if you are extending HttpServlet :well this is bit advanced process. when ever you are extending to HttpServlet, the service() method is written there.so we need to invoke that method. HttpServlet.service().
protected void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
The best part of this when the service method is called,it determines the request and which methods to be called.Say we have the method type is GET then doGet() method is called or else if we have post as request method then corresponding doPost() method is called.
Note: All these methods can be overridden.
The other methods inside a HttpServlet's service method are-