Basic JSP syntax knowledge and basic jsp syntax knowledge

Source: Internet
Author: User

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.





















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.