Animesh Gupta wrote:Hi All,
I am very new with servlet programming.
Welcome to the Ranch.
1.) I have seen the servlet API and whatever I see, like, Servlet, HttpServletRequest, HttpServletResponse, ServletRequest, ServletResponse, are all interfaces. Where is the concrete implementation for these interfaces ?
The concrete implementation for all of those (except for Servlet, which you provide) is provided by the container;
Tomcat for example. The fact that they are interfaces means that you have no need to be concerned about the concrete classes. You always code to the interface.
2.) I have read all around that servlet container creates the instance of the servlet. But, how does it do when javax.servlet.Servlet is an interface ?
You will proved concrete classes for the servlets by extending HttpServlet.
public void init(ServletConfig config) throws ServletException {
super.init(config);
Generally you will override the parameter-less version of init(). That way you don't have to worry about calling super.init().
My question is how does the servlet container know that init(), service() and destroy() methods are overridden under the class SimpleServlet, i.e., my custom class ?
It doesn't have to. That's the way that
Java works.
The servlet container creates and instance of javax.servlet.Servlet to call init(), service() and destroy() methods and not an instance of my class SimpleServlet. Then how does these methods get called ?
No, the container creates an instance of your SimpleServlet class.