Two: JSP script expression

Source: Internet
Author: User

JSP script expressions (expression) are used to output program data to the client

syntax: <%= variable or expression %>

Example: current time: <%= new Java.util.Date ()%>

JSP When the engine translates the script expression, it turns the program data into a string and then loses the data to the client at the appropriate location with Out.print (...).

You cannot have a semicolon (;)after a variable or expression in a JSP script expression.

Because it is such a out.println (variable or expression) that is displayed after translation;

Add ";", Java syntax error, out.println (new Date (););

and the JSP script fragment (scriptlet) is used to write multiple lines of Java code in a JSP page. Syntax:

<%

Multi-line Java code

%>

Note: The JSP script fragment can only appear in Java code, no other template elements , the JSP engine in the translation JSP page, the JSP script fragment will be placed in the Java code will be left intact to the servlet _ The Jspservice method.

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

You can have multiple script fragments in a JSP page that can embed text, HTML tags, and other JSP elements between two or more script fragments.

Example:

<%

int x = 10;

OUT.PRINTLN (x);

%>

<p> This is the JSP page text </p>

<%

int y = 20;

Out.println (y);

%>

code in multiple script fragments can access each other , like putting all the code in a pair of <%%> cases. such as:out.println (x);

Java script should not appear in the JSP in formal development: using label encapsulation technology

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, for example:

<%

for (int i=1; i<5; i++)

{

%>

<H1>www.it315.org</H1>

<%

}

%>

Print 5 lines www.it315.org

Two: JSP script expression

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.