JSP compiler based on the use of basic syntax in detail


There are five types of JSP compiler guidelines and instruction components. After JSP 1.0, most JSPS are included in a single tag that ends with. The new JSP 1.1 specification has been published, and it is also compatible with XML

The compiler guidelines for the five JSPS are as follows:

1. Compiler guidelines

2. Predefined

3. Formula

4. Program code

5. Notes

Let’s analyze a simple JSP page. You can create another directory under the examples directory of jswdk to store this file. The file name can be arbitrary, but the extension must be. JSP. As can be seen from the following code list, JSP pages have basically the same structure except that they have more java code than ordinary HTML pages. Java code is added to HTML code through <% and% > symbols. Its main function is to generate and display a string from 0 to 9. Before and after this string are some text output through HTML code.

Copy codeThe code is as follows:
< 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 to analyze.

First, JSP instructions. It describes the basic information of the page, such as the language used, whether to maintain session state, whether to use buffer, etc. The JSP instruction starts with <% @ and ends with% >. In this example, the instruction “<% @ pagelanguage =” Java “% >” simply defines that this example uses the Java language (currently, Java is the only supported language in the JSP specification).

Next is the JSP declaration. JSP declaration can be seen as a place to define variables and methods at the class level. JSP declaration starts with <%! And ends with% >. For example, the “<%! Stringstr =” 0 “;% >” in this example defines a string variable. Every declaration must be followed by a semicolon, just like declaring a member variable in a normal Java class.

The code block between <% and% > is 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 way to embed JSP generated values into HTML pages.