First, JSP comments in the page
(1) HTML annotations
<!--comment [<%=expression%>]--
A comment that can be displayed on the client, where all JSP script elements, instructions, and actions within the tag execute normally, meaning that the compiler scans the lines of code within the comment.
(2) Java Comment (implicit comment)
<%//comment%>
<%/*comment */%>
(3) JSP comment (implicit comment)
<%--comment--%>
Note: Characters marked with hidden comments are ignored at JSP compile time, and all JSP script elements, directives, and actions within the tag will not work. The JSP compiler does not compile statements between the annotations, and it does not appear in the client's browser.
Second, JSP Script Elements
<%! %> (statement)
Global variables, methods, and classes can be defined in this Scriptlet
<%=%> (expression)
The main function is to output a variable or a specific content
<%%> (script program)
In this scriptlet, you can define local variables, write statements, etc.
1. Declaration <%! %>
In a JSP file, you can declare one or more variables and methods at a time, separated by semicolons. When using the Java language when declaring, you must conform to the Java language specification.
Attention:
The variable must be declared before it can be used;
The declaration must end with a semicolon;
The variables or methods that have been declared in the package imported through the page directive can be used directly in the main JSP file;
JSP page member variables are variables that are shared by all users, and the result of any user action on a JSP page member variable will affect other users.
2. Expression <%=%>
An expression tag can contain any valid expression that conforms to the Java language specification;
The expression is used to evaluate, then its value is converted to a string, and inserted in the JSP file where the expression is displayed;
You cannot use semicolons as the end of an expression, however, in script segments <%......%> tags, the expression requires a semicolon to end.
3. Script <%%>
Multiple variables and methods can be declared in the script segment;
can use any valid expression;
Can contain any valid program fragment, as long as the Java itself conforms to the standard syntax;
<%%> cannot be nested in use;
HTML cannot be inserted between <%%>.
Iii. JSP Directive elements (directives)
Instruction (directives) is mainly used to provide information about the entire JSP page page, and to set the relevant properties of the JSP Web page. such as the encoding of Web pages, syntax, information and so on.
Start symbol:
<%@
Terminating symbol:
%>
In the text section: some instructions and a series of property settings
<%@ directive{attribute= "Value"}%>
Four, set the file encoding
ContentType CharSet refers to the encoding of the Web page content that the server sends to the client browser, pageencoding refers to the encoding used by the JSP file itself when it is stored.
In the JSP standard syntax, if the pageencoding attribute exists, then the character encoding of the JSP page is determined by pageencoding, otherwise it is determined by the charset of the ContentType attribute, if CharSet does not exist, The character encoding of JSP pages takes the default iso-8859-1.
Five, JSP Action Elements
include The action :<jsp:include> element allows for both dynamic and static files, both of which produce different results. If a static file is included, the content of the static file is added to the JSP Web page, and if it contains a dynamic file, the included file is also compiled by the JSP container.
Grammar:
<jsp:include page= "{Urlspec |<%=expression%>}" flush= "true | False "/>
Or
<jsp:include page= "{Urlspec |<%=expression%>}" flush= "true | False "/>
<jsp:paramvalue={"Value" | " <%=name%> "} name=" name "/>*
</jsp:include>
<jsp:include> has two properties: page and flush. Page: can represent a relative path, that is, the contained file location or the relative path of the expression operation; Flush: The accepted value is Boolean, assuming true, and will be emptied when the buffer is full. The default value is False.
<jsp:param> is used to pass one or more parameters to a JSP Web page.
The include directive tag is the first to merge the JSP page with the page to be embedded into a new JSP page, and then the JSP engine transforms the new page into a Java file for processing and running.
The Include action tag does not merge two pages when translating a JSP page into a Java file, but rather when the Java file's bytecode file is loaded and executed, the file introduced by the Include action tag is processed.
forward Action
<jsp:forward> definition: Transfer requests from the client to another JSP page from one JSP page.
Grammar:
<jsp:forwardpage={"URL" | "<%=expression%>"}/>
Or
<jsp:forward page ={"URL" | " <%=expression%> "}>
<jsp:param value={"Value" | <%=name%> "} name=" name "/>
</jsp:forward>
If you add the <jsp:param> tag, you can pass parameters or values to the target file.
Properties: page. The value of the page can be a relative path, that is, the address of the Web page you want to re-orient, or a relative path that is evaluated by an expression.
This action belongs to the server-side jump.
JSP Syntax Basics (i)