Basic syntax
There are five types of JSP compiler guidance and Directive elements. after JSP 1.0, most of the JSP is contained in a single tag with <% as the start %> as the end. the new JSP 1.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 <% @ compiler guide %>
2 pre-defined <%! Predefine %>
3 formula <% = formula %>
4 Program Code <% Program code %>
5 annotation <% -- 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.
<HTML>
<Head> <title> JSP page </title> <Body>
<% @ Page Language = "Java" %>
<%! String STR = "0"; %>
<% For (INT I = 1; I <10; I ++ ){
STR = STR + I;
} %>
Before JSP output.
<P>
<% = STR %>
<P>
After JSP output.
</Body>
</Html>
This JSP page can be analyzed in several parts.
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 "<% @ page Language =" 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, "<%! String STR = "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.
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.