JSP script elements and comments

Source: Internet
Author: User
Tags html comment

Today, I reviewed the JSP script elements and comments, and wrote the case. After debugging, the overall summary is as follows,

1. JSP statement:

<%! Statement %>

The variable in the declarative statement is a global variable. When multiple users execute this JSP page, the variable is shared.

For example:


<Head>

<Title> JSP Demo </title>

</Head>

<Body>

<%! Int I = 1% type = "codeph" text = "/codeph">


</Body>

2. JSP Scriptlets:

<% Java code %>

The JSP Scriptlets can contain multiple statements, such as methods, variables, and expressions;

For example:

 

<Head>

<Title> JSP Demo </title>

</Head>

<Body>


<%

String str = "Hello, xiaomo! ";

Out. println (str );

%>

</Body>

3. JSP expressions:

<% = Java code %>

In a simple form of output, there must be a value that can be output. The code in the expression is executed first, and then converted to a string to be displayed on the page.


For example:

 

<Head>

<Title> JSP Demo </title>

</Head>

<Body>


<% String str = "Hello, xiaomo! "; %>

<% = Str %>

</Body>

4. JSP comments:

<! --> HTML comment, which is displayed on the client;

<% -- %> JSP comment, not displayed on the client;

 

Related Article

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.