Detailed description of JSP compiler-based basic syntax

Source: Internet
Author: User

There are five types of JSP compiler guidance and Directive elements. after JSP1.0, most of the JSP files are contained in a single tag ending. the new JSP1.1 specification has been published, and it is also compatible with XML.

The compiler guide for the five JSP types is as follows:

1. compiler Guide

2. pre-defined

3. Formula

4. program code

5. Annotation

Next we will analyze a simple JSP page. You can create another directory in the examples directory of JSWDK to store this file. The file name can be arbitrary, but the extension must be. jsp. From the code list below, we can see that JSP pages have the same structure except Java code more than ordinary HTML pages. Java code is added to the HTML code through the <% and %> symbols. Its main function is to generate and display a string from 0 to 9. The front and back of this string are some text output through HTML code.
Copy codeThe Code is as follows:
<HTML>
<HEAD> <TITLE> JSP page </TITLE> </HEAD>
<BODY>
<% @ Page language = "java" %>
<%! String str = "0"; %>
<% For (int I = 1; I <10; I ++ ){
Str = str + I;
} %>

Before JSP output.
Copy codeThe Code is as follows:
<P>
<% = Str %>
<P>

After JSP output.
Copy codeThe Code is as follows:
</BODY>
</HTML>

This JSP compiler page can be divided into several parts for analysis.

The first is the JSP command. It describes the basic information of the page, such as the language used, whether to maintain the session status, and whether to use buffering. JSP commands start with <% @, and end with %>. In this example, the command "<% @ pagelanguage =" java "%>" only briefly defines the Java language used in this example (currently, java is the only supported language in JSP specifications ).

The following is the JSP declaration. The JSP declaration can be seen as a place where variables and methods at the class level are defined. JSP declaration by <%! Start, %> end. In this example, "<%! Stringstr = "0"; %> "defines a string variable. Each declaration must be followed by a semicolon, just like declaring a member variable in a common Java class.

The code block between <% and %> is the Java code that describes the JSP page processing logic, as shown in the for loop in this example.

Finally, the Code between <% = and %> is called a JSP expression, as shown in "<% = str %>" in this example. JSP expressions provide a simple method to embed JSP-generated values into HTML pages.

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.