| Evolution of Web Application |
| |
| How JSP and JSP Container function? |
| |
| |
| A JSP page is executed in a JSP container or a JSP engine, which is installed in a web server or in an application server. |
|
|
| |
| When a client asks for a JSP page the engine wraps up the request and delivers it to the JSP page along with a response object. The JSP page processes the request and modifies the answer object to integrate the communication with the client. The container or the engine, on getting the response, wraps up the responses from the JSP page and delivers it to the client. The abstractions of the request and response are the same as the ServletRequest and ServletResponse respectively. If the protocol used is HTTP, then the corresponding objects are HttpServletRequest and HttpServletResponse. |
| |
| The first time the engine intercepts a request for a JSP, it compiles the JSP page and other files into a class file that implements the servlet protocol. If the dependent files are other JSPs they are compiled into their own classes. |
| |
|
| The servlet class generated at the end of the translation process must extend a superclass that is either : |
1. It is specified by the JSP author through the use of the extends attribute in the page directive or
2. It is a JSP container specific implementation class that implements javax.servlet.jsp.JspPage interface and provides some basic page specific behavior. |
| |
| As JSP pages use HTTP, their implementation classes actually implement the javax.servlet.jsp.HttpJspPage interface, which is a sub interface of javax.servlet.jsp.JspPage. |
| |
| |
| The javax.servlet.jsp.JspPage interface contains two methods: |
1. public void jspInit() - It is invoked when the JSP is initialized and the page are free to provide initialization of the JSP by implementing this method in their JSPs.
2. public void jspDestroy() - This method is invoked when the JSP is about to be destroyed by the container. |
| |
| |
| The javax.servlet.jsp.HttpJspPage interface contains one method: |
| public void _jspService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException |
| This method generated by the JSP container is invoked, every time a request comes to the JSP. The request is processed and the JSP generates appropriate response. This response is taken by the container and passed back to the client. |
| |
| |
|
| |
|
| |
| |
| |