The Life Cycle of a JSP Page
The Life cycle of JSP can be defined ad the entire process from its creation to till destruction which is similar to servlet life cycle with an additional step which is required to compile JSP into servlet.A JSP page services requests as a Servlet. Thus, the life cycle and many of the capabilities of JSP pages are determined by Java servlet technology.
When a request is mapped to a JSP page, the web container first checks whether the JSP page’s servlet is older than the JSP page. If the servlet is older, the web container translates the JSP page into a servlet class and compiles the class. During development, one of the advantages of JSP pages over servlets is that the build process is performed automatically.
Path in life cycle of JSP
- Translation of JSP Page
- Complilation of JSP Page
- Loads the JSP page’s servlet class
- Instantiates an instance of the servlet class
- Initializes the servlet instance by calling jspInit method
- The container invokes the _jspService method, passing request and response objects
- If the container needs to remove the JSP page’s servlet, it calls the jspDestroy method.
JSP Translation and Compilation
During the translation phase each type of data in a JSP page is treated differently. Static data is transformed into code that will emit the data into the response stream. JSP elements are treated as follows:- Directives are used to control how the web container translates and executes the JSP page.
- Scripting elements are inserted into the JSP page’s servlet class.
- Expression language expressions are passed as parameters to calls to the JSP expression evaluator.
- jsp:[set|get]Property elements are converted into method calls to JavaBeans components.
- jsp:[include|forward]elements are converted into invocations of the Java Servlet API.
- The jsp:plugin element is converted into browser-specific markup for activating an applet.
- Custom tags are converted into calls to the tag handler that implements the custom tag.
apache-tomcat-7.0.54/work/Catalina/localhost/WAR-NAME/pageName_jsp.java
Both the translation and the compilation phases can yield errors that are observed only when the page is requested for the first time. If an error is encountered during either phase, the server will return JasperException and a message that includes the name of the JSP page and the line where the error occurred.
After the page has been translated and compiled, the JSP page’s servlet follows the servlet life cycle described in Servlet Life Cycle:
1.If an instance of the JSP page’s servlet does not exist, the container:
- Loads the JSP page’s servlet class
- Instantiates an instance of the servlet class
- Initializes the servlet instance by calling the jspInit method
If the container needs to remove the JSP page’s servlet, it calls the jspDestroy method.
0 comments:
Post a Comment