In the previous tutorial, we used java. util. Date. Someone may ask: why not only use import java. util? In fact, the import statement can also be used in JSPs, but its syntax is somewhat different from that of common Java. The following is an example:
<% @ Page import = "java. util. *" %>
<HTML>
<BODY>
<%
System. out. println ("Evaluating date now ");
Date date = new Date ();
%>
Hello! The time is now <% = date %>
</BODY>
</HTML>
The first line in the above Code calls a "directive ". This JSP "directive" starts with the <% @ character. This is a "page ctictive ". This "page ctictive" can contain all introduced projects. If you want to introduce more than one project, you can use commas (,) to separate projects. For example:
<% @ Page import = "java. util. *, java. text. *" %>
There can be multiple JSP ctives Ves in "page ctictive. In addition to "page ctictive", other useful ves include and taglib. In the subsequent tutorial, we will discuss taglib in detail. Here we will only discuss include direve ve.
Include directive should generally include the content of another file. The contained file can be HTML, JSP, and other types of files. The result is like that the original JSP file contains the included text. To see the include ctictive function, we create a new JSP:
<HTML>
<BODY>
Going to include myjsp. jsp... <BR>
<% @ Include file = "myjsp. jsp" %>
</BODY>
</HTML>
After writing the code, you can check the JSP in the browser. You will find that the original myjsp. jsp is included in the new JSP.
Finally, we will show the exercises in this section: modify some previous exercises and introduce the java. util package.