JSP Syntax Summary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.