Jspinit (), _ jspservice (), jspdestroy ()

Source: Internet
Author: User

Jspinit () {}: this method is called when the JSP page is initialized, and this method is only executed once during initialization. Therefore, you can perform one-time jobs such as initialization parameter configuration here, created by the author
Jspdestroy () {}: this method is called when the JSP page is disabled for some reason. It is created by the author.
Jspservice () {}: the JSP page processing method automatically created by the JSP Container, which is created by the JSP Container and cannot be defined by the author.
When the JSP file is processed for the first time, it is converted into a servlet. The JSP Engine first converts the JSP file into a Java source file. If an error occurs during the conversion process, it immediately terminates the file and sends an error message report to the server and client; if the conversion is successful, a class will be generated. Then create a servlet object. First, execute the jspinit () method to initialize the object. Since the jspinit () method only runs once, therefore, you can perform some necessary operations in this method, such as connecting to the database and initializing some parameters, and then execute the _ jspservice () method to process client requests, A thread will be created for each request. If multiple requests need to be processed at the same time, multiple threads will be created. Because the servlet is stored in memory for a long time, the execution speed is fast, however, because initialization requires compilation, the first execution is still slow. If the JSP page is closed or destroyed for some reason, the jspdestroy () method will be executed.
Jspinit () and jspdestroy () must be written in <%! %>. Note that there are! Symbol.
<%!
Public void jspinit (){
Super. jspinit ();
System. Out. println ("JSP initialized ");
}
%>
Note the preceding method. If the option executed during JSP syntax validator build is checked in the validation configuration in eclipse, an error is returned when verifying JSP syntax during build, prompting super. jspinit () does not have this method. The JSP page inherits from the httpservlet class, but httpservlet does not have the jspinit () method. The jspinit () method exists in the jsppage interface. The tool thinks this is wrong, while the super. jspinit () method does not make errors in the actual running environment. Another problem still exists when verifying JSP syntax during build. If a JSP file includes another JSP page and the local variables on the main JSP page are directly used in the included JSP page, the system will prompt that the local variable is undefined, which is acceptable at runtime. In addition, to reduce
Build time. Generally, verification during build can be set to disabled.

Method: Start myeclipse-> Project-> properties-> myeclipse-> Validation-> cancel the build tag of JSP syntax validation.

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.