js| syntax
The JSP compiler guidelines and instruction components have five types. After JSP 1.0, most of the JSPs are included in a single label that ends with <% as the starting%>. The new JSP 1.1 specification has been published and is also compatible with XML.
The compiler guidelines for the five types of JSPs are as follows:
1 Compiler Guidelines <%@ compiler guidelines%>
2 Predefined <%! Predefined%>
3 op-<%= expression%>
4 program Code <% program code%>
5 Annotation <%--Annotation--%>
Below we analyze a simple JSP page. You can create another directory in the JSWDK examples directory where the file name can be arbitrary, but the extension must be. jsp. As you can see from the code listing below, the JSP page has essentially the same structure as a few more Java code than a normal HTML page. Java code is added to the HTML code by <% and%> notation, and its main function is to generate and display a string from 0 to 9. At the front and back of this string are some text that is output through the HTML code.
< html>
< head>< title>jsp Page </title>< body>
<%@ page language= "java"%>
<%! String str= "0"; %>
<% for (int i=1 i < i++) {
str = str + i;
}%>
JSP output before.
< p>
<%= str%>
< p>
After the JSP output.
</body>
This JSP page can be divided into several sections to analyze.
The first is the JSP directive. It describes the basic information about the page, such as the language used, whether the session state is maintained, whether buffering is used, and so on. The JSP instruction begins with the <%@, and the%> ends. In this case, the directive "<%@ page language=" java "%>" simply defines the Java language used in this example (Currently, Java is the only supported language in the JSP specification).
The next is the JSP declaration. A JSP declaration can be viewed as a place to define variables and methods at this level of class. JSP declaration by <%! Start,%> end. As in this example, "<%!" String str= "0"; %> "defines a string variable. After each declaration, you must have a semicolon, just as you would declare a member variable in a normal Java class.
Code blocks between <% and%> are Java code that describes the processing logic of JSP pages, as shown in the For loop in this example.
Finally, the code between <%= and%> is called a JSP expression, as shown in the "<%= str%>" in this example. A JSP expression provides a simple way to embed a JSP-generated value into an HTML page.