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.