Basic JSP knowledge _ 2, jsp_2
I. JSP template Elements
Static HTML content on a JSP page is called a JSP template element.
Ii. JSP expression (expression)
A Simplified Method of outputting the computing results of a java variable or expression to the client. The variables or expressions to be output are directly encapsulated in <% = and %>.
The calculation result of variables or expressions in JSP expressions is converted into a string, and then inserted into the corresponding position of the output result of the entire JSP page.
Variables or expressions in JSP expressions cannot be followed by semicolons (;). JSP expressions are translated into an out. print (...) Statement
Iii. JSP script snippets (scriptlet)
One or more Java program codes nested in <% and %>
The Java code in the JSP script segment will be moved to the _ jspService method of the Servlet translated from the JSP page. Therefore, JSP script snippets can only be program code that meets Java syntax requirements
Any text, HTML tags, and other JSP elements other than the script snippets will also be converted into the corresponding Java program code and inserted into the _ jspService method, without changing the location of the script Fragment
Java code in JSP script snippets must strictly follow the Java syntax. For example, each command execution statement must end with a semicolon (;).
A JSP page can contain multiple script fragments (each of which is nested between an independent pair of <% and %> ), text, HTML tag, and other JSP elements can be embedded between two or more script fragments.
Code in multiple script fragments can be accessed from each other
The Java statements in a single script fragment can be incomplete. However, after combining multiple script fragments, the result must be a complete Java statement.
Iv. JSP Declaration
The JSP declaration encapsulates Java code in <%! And %>, the code in it will be inserted into the Servlet's _ jspService method.
JSP declarations can be used to define static code blocks, member variables, and methods of Servlet programs converted from JSP pages (almost none in JSP)
5. JSP comments
<% -- Comment -- %> JSP comment
When the JSP Engine translates a JSP page into a Servlet program, it ignores the commented content on the JSP page.
<! -- Comment --> HTML comment
Difference: JSP comments can annotate Java code, while HTML comments cannot.