JSP script expressions (expression) are used to output program data to the client
syntax: <%= variable or expression %>
Example: current time: <%= new Java.util.Date ()%>
JSP When the engine translates the script expression, it turns the program data into a string and then loses the data to the client at the appropriate location with Out.print (...).
You cannot have a semicolon (;)after a variable or expression in a JSP script expression.
Because it is such a out.println (variable or expression) that is displayed after translation;
Add ";", Java syntax error, out.println (new Date (););
and the JSP script fragment (scriptlet) is used to write multiple lines of Java code in a JSP page. Syntax:
<%
Multi-line Java code
%>
Note: The JSP script fragment can only appear in Java code, no other template elements , the JSP engine in the translation JSP page, the JSP script fragment will be placed in the Java code will be left intact to the servlet _ The Jspservice method.
The Java code in the JSP script fragment must strictly follow the Java syntax, for example, each execution statement must end with a semicolon (;).
You can have multiple script fragments in a JSP page that can embed text, HTML tags, and other JSP elements between two or more script fragments.
Example:
<%
int x = 10;
OUT.PRINTLN (x);
%>
<p> This is the JSP page text </p>
<%
int y = 20;
Out.println (y);
%>
code in multiple script fragments can access each other , like putting all the code in a pair of <%%> cases. such as:out.println (x);
Java script should not appear in the JSP in formal development: using label encapsulation technology
The Java statements in a single script fragment can be incomplete, but the result of a combination of multiple script fragments must be a complete Java statement, for example:
<%
for (int i=1; i<5; i++)
{
%>
<H1>www.it315.org</H1>
<%
}
%>
Print 5 lines www.it315.org
Two: JSP script expression