Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
JS Now you are writing the JSP to become a class definition. All the scriptlets you write will be placed into one of the methods of this class. Again, you can add variables and methods to declare them in this class. Of course, you can also use these variables and methods from scriptlets and expressions.
In order to add a statement, you must use the <%! and%> to circle your statement, such as:
<%@ page import= "java.util.*"%>
Date thedate = new Date ();
Date GetDate ()
System.out.println ("in GetDate () method");
Hello! The time was now <%= getDate ()%>
The above example has declared variables and methods: A Date variable thedate and a method getdate. These two are valid from now on in both scriptlets and expressions, because they are already defined.
Unfortunately, the above example does not work: No matter how you overload the page, the date is the same. The reason for these statements is that they are only counted once when the Web page is loaded. It's like we create a class in Visual C + + and define the initialization value of the variable.
The practice in this tutorial is to modify the example above and add another function computedate to reinitialize the thedate. and add a scriptlet to call computedate each time.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.