JSP basic Knowledge _2

Source: Internet
Author: User

One. JSP template elements

The static HTML content in a JSP page is called a JSP template element

Two. JSP expressions (expression)

A simplified way of outputting the computed result of a Java variable or expression to the client, and the variable or expression it will output is directly encapsulated in <%= and%>

The result of a variable or expression in a JSP expression is converted to a string and then inserted into the corresponding location of the entire JSP page output.

A variable or expression in a JSP expression cannot be followed by a semicolon (;), and the JSP expression is translated into a out.print (...) in the servlet program. Statement

Three. JSP script fragment (Scriptlet)

One or more Java program code nested within <% and%>

The Java code in the JSP script fragment will be moved unaltered into the _jspservice method of the servlet translated by the JSP page, so that the JSP script fragment can only be a program code that conforms to the Java syntax requirements.

Any text, HTML tags, and other JSP elements that are outside of the script fragment are also converted into the appropriate Java program code to be inserted into the _jspservice method, with the location of the script fragment unchanged

The Java code in the JSP script fragment must strictly follow the Java syntax, for example, after each command execution statement must end with a semicolon (;)

There can be multiple script fragments in a JSP page (each script fragment code is nested between separate pairs of <% and%>), and text, HTML tags, and other JSP elements can be embedded between two or more script fragments.

Code in multiple script fragments can access each other

The Java statements in a single script fragment can be incomplete, but the result of a combination of multiple script fragments must be a complete Java statement

Four. JSP declaration

JSP declaration encapsulates Java code in <%! And%>, the code inside it will be inserted outside the servlet's _jspservice method.

JSP declarations can be used to define static code blocks, member variables, and methods for a servlet program that is converted to a JSP page (almost unused in JSP)

Five. JSP annotations

<%--Comment Information--%> jsp comments

The JSP engine ignores the annotated content in the JSP page when translating the JSP page into a servlet program

<!--comment information--HTML comment

The difference: JSP annotations can annotate Java code, and HTML annotations can not

JSP basic Knowledge _2

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.