JSP life cycle and how it works

Source: Internet
Author: User

How the

JSP Works
JSP is a servlet, but it doesn't work the same way as HttpServlet. HttpServlet is first compiled into a class file by the source code
and then deployed to the server, after the first compilation. The JSP is first deployed and compiled into a class
file, the first deployment of the JSP will be compiled when the client first request the JSP file as the Httpjsppage class is a subclass of the
servlet. This class is temporarily stored in the server's working directory by the server.
The following is a description of the JSP compilation process. When the client first requests greeting.jsp, Tomcat first translates the greeting.jsp
into the standard Java source code greeting.jsp.java, stored in C:\apache-tomcat-6.013 (related version number
in the \work\catalina\locahost\jsp\or\apache\jsp directory, and compile Greeting_jsp.java as a class file Greetimg
_ Jsp.class. The class file is the servlet corresponding to the JSP. After compiling, run the class file to respond to client requests.
After clients access greeting.jsp, the server will no longer recompile the JSP file but call Greeting_jsp.class
directly in response to the client request.
because the JSP will only be compiled at the time the client first requests it, the first request will be slower, and then the speed increased
. If you delete a tomcat-saved JSP-compiled class file, Tomcat will recompile the JSP
JSP's life cycle
JSP is also a servlet, and there will only be one instance at run time. Like a servlet, a JSP instance is initialized, and the Init () and Destory () methods of the servlet
are called when destroyed. In addition, it has its own initialization method and destruction method _jspinit () and _jspdestroy ()
For example
<% page language = "java" contenttype= "text/html;charset= UTF-8 "%>
<%public void _jspinit () {
Related initialization code}
public void _destroy () {
Code to run when destroying}
%> 

JSP life cycle and how it works

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.