JSP integrates Java code and HTML code. As a result, the JSP syntax is much like the HTML code. The difference between JSP code and HTML file is mainly reflected in the following points:
1.JSP-expression
Role: A JSP expression is used to output the value of a variable or the value of an expression to a browser.
Syntax: <%= variable or expression%>.
Note: Do not answer the semicolon after the expression.
Principle: The JSP engine outputs the results of the JSP expression calculation using the Out.write () method.
For example: The <%= "HelloWorld"%> JSP engine will output the line code using Out.write ("HelloWorld") on the browser side.
Script for 2.JSP
Role: JSP scripts can nest Java code in an HTML document.
Syntax: <%
Java code
%>
Principle: The JSP engine copies the Java code as it is in the _jspservice method of the Java class that the JSP translates into.
3.JSP annotations
JSP annotations are ignored by the JSP engine.
Statement of the 4.JSP
Syntax: <%! Variable name or method%>
Effect: Translates a variable or method into a member variable or method (the Servlet class of a JSP object).
Principle: Copy the code into the class scope, not in a method body.
Interview questions:
int a = 1; int b = 1; %><% a++; b+ +; %>= <%=a%> <br>= <%=b%>
When a user browses the page and refreshes continuously, the value of a is incremented, and the value of B is always equal to 2. Because A is a member variable, b is a local variable.
JSP Syntax Summary