Basic knowledge of JSP syntax

Source: Internet
Author: User

1. JSP annotations

There are two main types of annotations in JSPs:

 Explicit Comment: <!--HTML Comment, client visible--(heavier transport burden, minimal use)
 implicit annotations:
 Format one://single-line comment
 Format two:/* */single-line or multiline comment
 Format three: <%--jsp comment, client not visible--%> JSP Comment
Example:
Write a JSP file that contains the above three types of annotations



2. Scriptlet (Script applet)

All Java programs that are embedded in HTML code must be marked with Scriptlet.
Scriptlet includes: small scripts, declarations, and expressions, which are described separately below.


(1) Small script: <%java code%>

 can write various statements in our Java application methods, including defining variables, but cannot write methods.
 Reason: The code will be converted into a method body in a class by the JSP engine, if the method is written, it is equivalent to the method body
Declares a method, so you cannot write a method in a small script.

For example:

In the JSP page, ask for 1-100 summation and output in the page:



(2) Statement: <%! Method%>

 define global constants, write methods, but not directly in <%! %> write any ordinary statement, because this part will be the JSP
The engine is converted into a method in a class.
 Note: JSP built-in objects cannot be used in this section.

For example:
Declares a method that formats a date, and the call displays the current date.




(3) Expression: <%=%>

 output A variable or a specific content.

For example:
It is better to use Out.print () and expressions to print a table of 10 rows and 10 columns on the page, respectively.
Out.print () Output:



Expression output: More concise, the foreground code is more structured, so recommend this way.





















Basic knowledge of JSP syntax

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.