In the above tutorial, we have learned how to embed a Java expression between the <% = and %> character series in a JSP webpage. However, it is very difficult to do a lot of programming by placing Java expressions in HTML.
JSP also allows you to write JavaCodeBlocks are embedded in JSP. Specifically, place the Java code segment between the characters <% and %>. In fact, it is the same as the expression, but there is no equal sign at the beginning.
A code block is a well-known "scriptlet ". Scriptlet alone does not play any role in HTML. Every time the scriptlet contains the executed Java code, JSP is called.
The following code is the modified Code of the previous JSP tutorial. We added a scriptlet:
<HTML>
<Body>
<%
// This Is A scriptlet. notice that the "date"
// Variable we declare here is available in
// Embedded expression later on.
System. Out. println ("Evaluating date now ");
Java. util. Date = new java. util. Date ();
%>
Hello! The time is now <% = date %>
</Body>
</Html>
If you run the preceding example, you will notice that "system. Out. println" is output in the server log. This is a convenient method for some simple debugging. Some servers have the JSP debugging function in IDE. You can refer to the server documentation to check whether this function is available.