Basic JSP knowledge _ 2, jsp_2

Source: Internet
Author: User
Tags html comment

Basic JSP knowledge _ 2, jsp_2
I. JSP template Elements

Static HTML content on a JSP page is called a JSP template element.

 

Ii. JSP expression (expression)

A Simplified Method of outputting the computing results of a java variable or expression to the client. The variables or expressions to be output are directly encapsulated in <% = and %>.

The calculation result of variables or expressions in JSP expressions is converted into a string, and then inserted into the corresponding position of the output result of the entire JSP page.

Variables or expressions in JSP expressions cannot be followed by semicolons (;). JSP expressions are translated into an out. print (...) Statement

Iii. JSP script snippets (scriptlet)

One or more Java program codes nested in <% and %>

The Java code in the JSP script segment will be moved to the _ jspService method of the Servlet translated from the JSP page. Therefore, JSP script snippets can only be program code that meets Java syntax requirements

Any text, HTML tags, and other JSP elements other than the script snippets will also be converted into the corresponding Java program code and inserted into the _ jspService method, without changing the location of the script Fragment

Java code in JSP script snippets must strictly follow the Java syntax. For example, each command execution statement must end with a semicolon (;).

A JSP page can contain multiple script fragments (each of which is nested between an independent pair of <% and %> ), text, HTML tag, and other JSP elements can be embedded between two or more script fragments.

Code in multiple script fragments can be accessed from each other

The Java statements in a single script fragment can be incomplete. However, after combining multiple script fragments, the result must be a complete Java statement.

 

Iv. JSP Declaration

The JSP declaration encapsulates Java code in <%! And %>, the code in it will be inserted into the Servlet's _ jspService method.

JSP declarations can be used to define static code blocks, member variables, and methods of Servlet programs converted from JSP pages (almost none in JSP)

 

5. JSP comments

<% -- Comment -- %> JSP comment

When the JSP Engine translates a JSP page into a Servlet program, it ignores the commented content on the JSP page.

<! -- Comment --> HTML comment

Difference: JSP comments can annotate Java code, while HTML comments cannot.

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.