WebContainer
Tomcat Jar
J2EE specifications
servlet-api.jar
Implementation
catalina.jar
Inheritance hierarchy Request Object
ServletRequest(Interface)
HttpServletRequest(Interface)
HttpServletRequestWrapper(Class)
Similarly, for Response Object, i.e., replace Request with Response.
How web Container calls service method?
Web container interacts with
public service(rq, rs)
which internally calls theprotected service(rq,rs)
of the HttpServlet class.
/* No need to override this */
public void service(ServletRequest req,ServletResponse res) throws ServletException, IOException
/* No need to override this */
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
/*
Internally, it calls protected do*** method of
abstract HttpServlet Class
*/
Servlet - JDBC Integration
Layers involved :
Servlet ↴ DAO (Uses DBUtils) ↴ POJO ↴ Database
Note: JDBC Jar can be placed either in <WEB-INF>/lib
folder in IDE created project structure OR <tomcat>/lib
folder under tomcat installation folder.
ServletException
/*Checked Exception*/
javax.servlet.ServletException
/*Preferred exception constructor*/
public ServletException(String message, Throwable rootCause);
Defines a general exception a servlet can throw when it encounters difficulty.
During Initialization by init() style method always throw Serlvet Exception to let Web Container know some Exception(anamoly) has occured.
Similarly, in destroy() style method always catch
checked exception
and convert it intounchecked Exception
to let the web container know that some exception occured during destruction of Web Servlet.
Last updated