Basic JSP syntax knowledge and basic jsp syntax knowledge
1. JSP comments
Comments in JSP are classified into two categories:
Explicit comment: <! -- HTML comment, visible on the client --> (increase the transmission burden and minimize the use of data)
Implicit comment:
Format 1: // single line comment
Format 2:/**/single-line or multi-line comment
Format 3: <% -- JSP annotation, invisible to the client -- %> JSP Annotation
Example:
Compile a JSP file that contains the preceding three annotations
2. Scriptlet (script applet)
All Java programs embedded in HTML code must be marked with Scriptlet.
Scriptlet includes: Small scripts, declarations, and expressions.
(1) Small Script: <% Java code %>
Compile can write various statements in our Java application methods, including defining variables, but not methods.
Cause: the code will be converted into a method body in the class by the JSP Engine. If a method is written, it is equivalent
Declaration method, so the method cannot be written in a small script.
For example:
Calculate the sum of 1-100 on the Jsp page and output it on the page:
(2) Declaration: <%! Method %>
Compile defines global constants, writing method, but cannot be directly in <%! %> Write any common statement in it because this section is JSP
The engine is converted into a method in the class.
Note: JSP built-in objects cannot be used in this part.
For example:
Declare a method for formatting the date and call it to display the current date.
(3) expression: <% = %>
Outputs a variable or specific content.
For example:
Use out. print () and expression to print ten rows and ten columns of tables on the page. which method is better.
Out. print () output:
Expression output: it is more concise and the front-end code is more regular. Therefore, this method is recommended.