HTML comment
Display a comment on the client.
JSP syntax
<! -- Comment [<% = expression %>] -->
Example 1
<! -- This file displays the user login screen -->
Generate the same data as the above in the HTML source code of the client:
<! -- This file displays the user login screen -->
Example 2
<! -- This page was loaded on <% = (New java. util. Date (). tolocalestring () %> -->
In the HTML source code of the client, it is displayed:
<! -- This page was loaded on January 1, 2000 -->
Description
This annotation is similar to HTML, that is, it can be seen in "View Source Code.
The only difference is that you can use an expression in this comment (Example 2 ). This expression is indefinite. Different pages allow you to use various expressions as long as they are valid.
Hide comment: it is written in the JSP program but not sent to the customer.
JSP syntax
<% -- Comment -- %>
Example:
<% @ Page Language = "Java" %>
<HTML>
<Head> <title> A comment test </title> <Body>
<H2> A test of comments </H2>
<% -- This comment will not be visible in the page source -- %>
</Body>
</Html>
Description
Characters marked with hidden comments are ignored during JSP compilation. This annotation is useful when you want to hide or annotate your JSP program.
The JSP compiler does not compile the statements between <% -- and -- %>. It is not displayed in the client's browser, you can write comments between <% -- %> in the source code, but cannot use "-- %> ", if you want to use it, use "-- %/> ".
Declaration: declare valid variables and methods in JSP programs
JSP syntax
<%! Declaration; [Declaration;] +... %>
Example
<%! Int I = 0; %>
<%! Int A, B, C; %>
<%! Circle A = new circle (2.0); %>
Description
Declare the variables and methods you will use in the JSP program. You must do the same. Otherwise, an error will occur.
You can declare multiple variables and methods at a time, as long as they end with ";". Of course, these declarations are valid in Java.
When declaring methods or variables, pay attention to the following rules:
The declaration must end with ";" (scriptlet has the same rule, but the expression is different ).
You can directly use declared variables and methods included in <% @ Page %> without declaring them again.
A statement is valid only on one page. If you want to use some declarations for each page, you 'd better write them into a separate file and include them with the <% @ include %> or <JSP: Include> element.
Expression: contains an expression that complies with the JSP syntax.
JSP syntax
<% = Expression %>
Example
<Font color = "blue"> <% = map. Size () %> </font>
<B> <%. G = numguessethint () %> </B>.
Description
The expression element represents an expression defined in the script language. It is automatically converted to a string after running, and then inserted into the expression for display at the location of the JSP file. Because the value of this expression has been converted into a string, you can insert this expression in a line of text (in the same form as ASP ).
When using expressions in JSP, remember the following:
You cannot use a semicolon (";") as the expression Terminator. But the same expression must end with a semicolon when used in scriptlet! View the scriptlet expression element that can include any valid expressions in Java language specification.
Sometimes expressions can also be used as attribute values of other JSP elements. An expression can become very complex and may consist of one or more expressions. The order of these expressions is from left to right.
Scriptlet: contains a valid program segment.
JSP syntax
<% Code fragment %>
Example
<%
String name = NULL;
If (request. getparameter ("name") = NULL ){
%>
<% @ Include file = "error.html" %>
<%
} Else {
Foo. setname (request. getparameter ("name "));
If (FOO. getname (). inclusignorecase ("Integra "))
Name = "Acura ";
If (name. inclusignorecase ("Acura ")){
%>
Description
A scriptlet can contain multiple JSP statements, methods, variables, and expressions.
Because of scriptlet, we can do the following:
Declare the variables or methods to be used (refer to the Declaration ).
Compile JSP expressions (reference expressions ).
Use any implicit object and any object declared with <JSP: usebean>
Compile JSP statements (if you are using Java, these statements must comply with Java Language Specification ,).
Any text, HTML Tag, JSP element must be out of scriptlet
When the JSP receives a request from the customer, the scriptlet will be executed. If the scriptlet has the displayed content, the displayed content will be included in the out object.
Page command: defines the global attributes in the JSP file.
JSP syntax
<% @ Page
[Language = "Java"]
[Extends = "package. Class"]
[Import = "{package. Class | package. *},..."]
[Session = "True | false"]
[Buffer = "None | 8kb | sizekb"]
[Autoflush = "True | false"]
[Isthreadsafe = "True | false"]
[Info = "text"]
[Errorpage = "relativeurl"]
[Contenttype = "mimetype [; charset = characterset]" | "text/html; charset = ISO-8859-1"]
[Iserrorpage = "True | false"]
%>
Example
<% @ Page import = "Java. util. *, java. Lang. *" %>
<% @ Page buffer = "5kb" autoflush = "false" %>
<% @ Page errorpage = "error. jsp" %>
Description
<% @ Page %> the command acts on the entire JSP page, and also includes static inclusion files. However, the <% @ Page %> command cannot act on dynamic include files, such as <JSP: Include>
You can use multiple <% @ Page %> commands on a page, but the attributes can only be used once. However, there is an exception, that is, the import attribute. Because the import attribute is similar to the Import Statement in Java (refer to Java language), you can use this attribute several times.
No matter where you place the <% @ Page %> command in the JSP file, it applies to the entire JSP page. However, for the sake of readability and good programming habits of the JSP program, it is best to put it on the top of the JSP file.
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "C" %>
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix = "FMT" %>
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix = "FN" %>
Taglib command: defines a tag Library and the prefix of its custom tags.
JSP syntax
<% @ Taglib uri = "uritotaglibrary" prefix = "tagprefix" %>
Example
<% @ Taglib uri = "http://www.jspcentral.com/tags" prefix = "public" %>
<Public: loop>
.
.
</Public: loop>
Description
<% @ Taglib %> the command declares that the JSP file uses custom tags, reference the tag library, and specify the prefix of their tags.
Here, custom tags include tags and elements. Because JSP files can be converted to XML, it is important to understand the relationship between tags and elements. A tag is only a tag that is elevated in the sense and is part of a JSP element. JSP elements are part of the JSP syntax, and have the start tag and end tag like XML. An element can also contain other text, tags, and elements. For example, a JSP: plugin element has the <JSP: plugin> start tag and </jsp: plugin> end tag, and can also have <JSP: Params> and <JSP: fallback> element.
You must use the <% @ taglib %> command before using a custom tag, and you can use it multiple times on a page, but the prefix can only be used once.
Attribute
Uri = "uritotaglibrary"
The Uniform Resource Identifier (URI) uniquely names a custom tag Based on the tag prefix. The URI can be the following:
Uniform Resource Locator (URL), defined by RFC 2396, view the http://www.hut.fi/u/jkorpela/rfc/2396/full.html
Uniform Resource Name (URN), defined by RFC 2396
A relative or absolute path
Prefix = "tagprefix"
The prefix before the custom tag. For example, in <public: loop>, if public is not specified here, this is invalid. Do not use JSP, jspx, Java, javax, Servlet, sun, or sunw as your prefix.