Detailed usage of basic syntax based on JSP compiler

  • 2020-06-07 05:10:05
  • OfStack

There are 5 types of JSP compiler guidelines and instruction elements. After JSP1.0, most JSP are included in the single 1 tag to end with. The new JSP1.1 specification has been published and is also compatible with XML.

The guidelines for the five JSP compilers are as follows:

1. Compiler guidelines

2. The predefined

3. The operation type

4. Program code

5. Note

Let's analyze a simple JSP page. You can create another directory under examples's examples directory for this file, which can be named any way you want, but must have an extension of.jsp. As you can see from the code listing below, JSP pages have basically the same structure, except that they have 1 more Java code than regular HTML pages. The Java code is passed < % and % > Added to the middle of the HTML code, the symbol's main function is to generate and display a string from 0 to 9. The string is preceded and followed by 1 bit of text output via the HTML code.


< HTML> 
 < HEAD>< TITLE>JSP  page  < /TITLE>< /HEAD> 
 < BODY> 
 < %@ page language="java" %> 
 < %! String str="0"; %> 
 < % for (int i=1; i < 10; i++) { 
         str = str+ i;  
    } %>

JSP before output.

 < P> 
 < %= str %> 
 < P> 

JSP after output.

< /BODY> 
< /HTML>

The JSP compiler page can be analyzed in several sections.

The first is the JSP directive. It describes the basic information of the page, such as the language used, whether session state is maintained, whether buffering is used, and so on. JSP instruction by < %@ start, % > The end. In this case, the instruction" < %@pagelanguage="java"% > It simply defines that this example USES the Java language (currently, Java is the only language supported in the JSP specification).

The JSP declaration follows. The JSP declaration can be seen as a place to define variables and methods at this level of the class. JSP statement by < %! To start, % > The end. As in this example" < %!Stringstr="0";% > "Defines a string variable. Each declaration must be followed by a semicolon, just as the member variable 1 is declared in the ordinary Java class.

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

Finally, at < % = and % > The code between is called the JSP expression, as in this example" < %=str% > "As shown. JSP expressions provide a simple way to embed values generated by JSP into HTML pages.


Related articles: