What if we override the init(ServletConfig) and don't call super(ServletConfig)?
You may create a subclass which extends GenericServlet class. If you override init(ServletConfig) method and don't call super(servletConfig) then the ServletConfig reference is not stored in the GenericServlet and if we call getServletConfig() we get null.
The reason we're advised to add super.init(config) is because GenericServlet.init(ServletConfig) stores a copy of the ServletConfig so that its getInitParameter method can forward the call to the ServletConfig object. If you override init(ServletConfig) in your own code you should add super.init(config) to preserve that functionality.
Another method GenericServlet.init() is provided as a convenience. GenericServlet.init(ServletConfig) internally calls GenericServlet.init(). If you want to add functionality at init-time, you should do it by overriding init(). The default implementation of init(ServletConfig) will save the ServletConfig reference and then call your overriding init().
Most Recent servlet Faqs
- What is the getInputStream() of ServletRequest for?
- How to get the client information in a Servlet?
- Can I control Session timeout?
- What is the difference between RequestDispatcher's forward method and HttpServletResponse's sendRedirect method?
- When do I use HttpSessionListener?
- What is the difference between the request attribute and request parameter?
- What is the defferent between getNamedDispatcher() and getRequestDispatcher()?
Most Viewed servlet Faqs
- What is the difference between the request attribute and request parameter?
- When do I use HttpSessionListener?
- How to use ServletContext.getResourceAsStream(java.lang.String path)?
- What is the difference between RequestDispatcher's forward method and HttpServletResponse's sendRedirect method?
- Can I control Session timeout?
- How to get the client information in a Servlet?
- What is the defferent between getNamedDispatcher() and getRequestDispatcher()?