This article analyzes the basic syntax of JSP. Share it for your reference, as follows:
1. Instruction <%@ Instruction %>
JSP directives are the engine of JSP. They don't directly produce any visual output, they just indicate what the engine needs to do with the remaining JSP pages. The instruction is marked by <%@ ?%>. The two main instructions are page and include. This article does not discuss the directive taglib, but it is used when creating custom tags in JSP1.1.
Directive pages can be found at the top of almost all JSP pages. Although it is not necessary, you can define things like where to look for Java class support.
<%@ page import="" %>
Instructs where to direct network users when a Java runs problem occurs:
<%@ page errorPage="" %>
Whether information is required to be managed at the user session level, which is likely to span multiple web pages (more described in the section on JavaBeans):
<%@ page session="true" %>
The directive "include" can divide your content into more manageable elements, such as elements that include a normal page header or footer. The included web page can be a fixed HTML page or more JSP content:
<%@ include file="" %>
2. Declaration <%! Declaration %>
JSP declarations allow you to define page-level variables to save information or define the support methods that the remaining JSP pages may require. If you find yourself writing too much code, it is usually best to write it into a separate Java class. The declaration is defined by <%! ?%>. A Java statement that must be terminated by a semicolon, and any content must be valid:
<%! int i=0; %>
3. Expression <%= Expression %>
Through expressions in JSP, the result of the computed expression is converted into a string and directly included in the output page. JSP strings are marked by <%= ?%> tags and unless they are part of the string referenced, they do not include semicolons.
<%= i %> <%= "Hello" %>
4. Code segment/Script segment <% Code segment %>
A JSP code snippet or script snippet is embedded in the "<% ?%>" tag. This Java code runs when the web server responds to the request. Around the script snippets may be pure HTML or XML code, where code snippets can allow you to create conditional execution code, or just call another piece of code. For example, the following code combines expressions and script snippets to display the string "Hello" in the H1, H2, H3 and H4 tags. Script snippets are not limited to one line of source code:
<% for (inti=1; i<=4; i++) { %> <H<%=i%>>Hello</H<%=i%>> <% } %>
5. Comment <%-- Comment--%>
The last key element of JSP is about embedding comments. Although you can always include HTML comments in your file, users will see these comments once they view the page source code. If you don't want the user to see the comment, you should embed it into the <%-- ?--%> tag:
<%-- comment for server side only --%>
I hope this article will be helpful to everyone's JSP programming.