HTML Comment Displays a comment on the client.
JSP syntax
] ->
Example 1
Generate and the same data as above in the client's HTML source code:
Example 2
->
Displayed in the client's HTML source code:
Description / R
This annotation is very similar to HTML, that is, it can be seen in "View Source /".
The only difference is that you can use expressions in this comment. This expression is unclear, different from the page, you can use a variety of expressions, as long as it is legal. More please see the expression
Hidden comments
Write in the JSP program, but not send it to the customer.
JSP syntax
<% - comment -%>
example:
<% @ Page language = "java"%>
Description / R
The characters with hidden comments marked will be ignored when JSP compiles. This comment is useful when you want to hide or annotate your JSP program. The JSP compiler does not compile the statement between <% - and -%>, which does not display in the customer's browser, and will not see in the source code.
statement
Declaring the legal variables and methods in the JSP program
JSP syntax
<%! Declaration; [Declaration;] ...%>
example
<%! Int = 0;%>
<%! Int A, B, C;%>
<%! Circle a = new circle (2.0);%>
Description / R
Declare that variables and methods you will be used in the JSP program. You must do this, or you will be wrong.
You can declare multiple variables and methods in one time, as long as ";" is ending, of course, these statements are legal in Java.
Please pay attention to some of the following rules when you declare methods or variables:
The statement must be ";"; "Scriptlet has the same rule, but the expression is different).
You can use the declared variables and methods that have been included in <% @ Page%>, do not need to be re-declared.
A statement is only valid in one page. If you want each page to use some statements, it is best to write them into a separate file, then use <% @ include%> or
expression
Contains an expression that conforms to JSP syntax
JSP syntax
<% = Expression%>
example
<% = map.size ()%> font> <% = numguess.get ()%> b>.
Description / R
Expression elements indicate a expression that is defined in the scripting language, which is automatically converted to a string after running, and then inserted into this expression of the JSP file display. Because the value of this expression has been converted to a string, you can insert this expression in a line of text (the form and ASP is exactly the same).
Remember the following: When you use an expression in JSP:
You can't use a semicolon (";") as an expression of the expression. But the same expression is used in the scriptlet! View Scriptlet
This expression element can include any active expression in Java Language Specification.
Sometimes the expression can also be an attribute value of other JSP elements. An expression can become complicated, it may consist of one or more expressions, these expressions are from left to right.
[/ b] scriptlet [/ b]
Contains an effective block.
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 (). EqualsignoreCase ("Integra"))
Name = "acura";
IF (name.equalsignorecase ("acura")) {
%>
Description / R
A scripTlet can include multiple JSP statements, methods, variables, expressions
Because Scriptlet, we can do the following things:
Declare the variables or methods to be used (reference declarations).
Write a JSP expression (reference expression).
Use any implicit objects and any objects that use
Write a JSP statement (if you are using Java language, these statements must follow Java Language Specification,).
Any text, HTML tag, JSP element must be outside Scriptlet
When JSP receives a customer request, the scriptlet will be executed if the scriptlet has the content displayed, and the contents of these display are existing in the OUT object.
Include instruction
Contains a static file in the JSP while parsing the JSP statement in this file.
JSP syntax
<% @ Include file = "relativeURL"%>
example
INCLUDE.JSP:
<% @ Page import = "java.util. *"%> <% = (New java.util.date ()) .tolocalestring ()%>
Displays in the page:
THE CURRENT DATE AND TIME ARE
Aug 30, 1999 2:38:40
Description / R
<% @ include%> The instruction will insert a file containing text or code when the JSP is compiled. When you use <% @ include%> instruction, this containing process is static. Static container means that this file containing files will be inserted into the JSP file. This containable file can be a JSP file, an HTML file, a text file. If included is a JSP file, the code in this file containing the JSP will be executed.
If you just use INCLUDE to include a static file. The result of this containing files will be inserted into the JSP file. Once the included file is executed, the process of the primary JSP file will be recovered and the next line is proceed.
This containing files can be HTML files, JSP files, text files, or just a java code, but you have to pay attention to , html>,
, body> tag in this included file Because this will affect the same tag in the original JSP file, so sometimes it will cause errors.There are some <% @ include%> Directance behavior is based on special JSP compilation conditions, such as:
This included file must be open to all customers and must be valid, or it has secure limitations.
If this included file is changed, the JSP file containing this file will be recompiled.
Attributes:
FILE = "relativeurl"
This containing file path name is generally referring to the relative path, no port, protocol, and domain name, as follows:
"Error.jsp" "Templates / Onlinestore.html" "/ beans / calendar.jsp"
If this path starts with "/", this path is primarily referring to the up and down relationship path of the JSP application. If the path starts with a file name or directory name, then this path is the current path of the JSP file being used.
Page instruction
Define global properties 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 / R
<% @ Page%> The instruction acts on the entire JSP page, and also includes static include files. But <% @ Page%> The instruction does not work to dynamically contain files, such as
You can use multiple <% @ Page%> instructions in a page, but the properties can only be used once, but there is also an exception, that is the import property. Because the Import property and the Import statement in Java are almost almost (refer to Java Language), you can use this property several times.
Whether you put <% @ Page%> instructions in JSP files, its scope is entire JSP page. However, for the readability of the JSP program, and good program habits, it is best to put it on the top of the JSP file.
Attributes
Language = "java"
Declare the type of scripting language, you can only use "java"
Extends = "package.class"
The full name of Java Class, which is required to add JAVA Class, but use it carefully, which limits the compiletability of JSP.
Import = "{package.class | package. *}, ..."
A list of Java packages that require imported, these packets act on blocks, expressions, and declarations.
The following packages have been imported at the JSP compile, so you don't need to indicate again:
Java.lang. *
Javax.Servlet. *
Javax.Servlet.jsp. *
Javax.Servlet.http. *
session = "True | FALSE"
Set whether the customer needs http session. (If you have learned ASP, it should be no stranger to it) if it is True, then the session is useful.
If it has false, then you can't use the Session object, and define the
The default is True.
Buffer = "None | 8KB | SIZEKB"
The size of the buffer is used by the OUT object to handle the executionful JSP's output of the client browser. The default is 8KB
Autoflush = "True | FALSE"
Setup if the buffer overflows, if the value is required, if its value is defined as true (default), the output is normal, if it is set to false, if this buffer overflows, it will cause an unexpected error. If you put Buffer is set to none, then you can't set autoflush to false.istryreadsafe = "true | false"
Set whether the JSP file can be used multithreaded. The default is True, that is, JSP can handle a request for multiple users at the same time. If set to false, a JSP can only handle a request at a time.
INFO = "text"
A text will be joined in JSP in executing JSP, and you can retrieve it using the servlet.getServletInfo method.
ErrorPage = "relativeurl"
Set the JSP file for processing an exception event.
iSerrorPage = "True | FALSE"
Set whether this page is an error page, if set to true, you can use the Exception object.
ContentType = "MIMETYPE [; Charset = Characters" | "text / html; charSet = ISO-8859-1"
Set the MIME type. The default MIME type is: Text / HTML, the default character set is ISO-8859-1.
Redirect an HTML file, a JSP file, or a block.
JSP syntax
oral
Value = "{parameterValue | <% = express%>}" /> jsp: Forward> example jsp: Forward> Description / R You can send parameters and values to the target file, in this example, the parameters we passed are namedame, the value is Scott, if you use the If you use a non-buffered output, be careful when using Attributes Page = "{relativeURL | <% = expression%>}" Here is an expression or a string to explain the file or URL you will oriented. This file can be a JSP, block, or other file capable of handling the Request object (such as ASP, CGI, PHP). Send one or more parameters to a dynamic file, this file must be a dynamic file. If you want to pass multiple parameters, you can use multiple Get the properties of the bean, used to display in the page JSP syntax example
Calendar of
h2>
Description / R
This
You can't use
You can use
Attributes
Name = "beaninstancename"
Bean's name, by
Property = "PropertyName"
The attribute name of the specified bean.
skill:
In the JSP reference in Sun, if you use
Contains a static or dynamic file.
JSP syntax
oral
jsp: incrude>
Examples
jsp: incrude>
Description / R
You can't judge a file from a file name to be dynamic or static, such as aspcn.asp may just contain some information, without having to execute.
If this included file is dynamic, you can also pass the parameter name and parameter value with
Attributes
Page = "{relativeURL | <% = expression%>}"
The parameter is a relative path, or represents a relative path expression.
Flush = "True"
Here you must use flush = "true", you can't use false values. The default is false
You can use multiple
Execute an applet or bean, there is a possibility to download a Java plugin for execution it.
JSP syntax
TYPE = "bean | applet" Code = "ClassFileName" CodeBase = "classfiledirectoryname" [Name = "instancename"] [Archive = "Uritoarchive, ..."] [Align = "bottom | TOP | MIDDLE | LEFT | Right"] [Height = "displaypixels"] [Width = "displaypixels"] [Hspace = "LeftrightPixels"] [VSpace = "Topbottompixels"] [Jreversion = "jreversionnumber | 1.1"] [Nspluginurl = "urltoplugin"] [IEpluginURL = "URLTOPLUGIN"]> [ [ jsp: params>] [ jsp: plugin> example jsp: params> unable to load applet p> jsp: Fallback> jsp: plugin> Description / R When the JSP file is compiled, when sending to the browser, the In general, the Attributes TYPE = "bean | applet" The type of plug-in object that will be executed, you must specify this bean or applet because this property has no default. Code = "ClassFileName" The name of the Java Class will be performed by the Java plug-in, must end with .class. This file must exist in the directory specified by the CodeBase property. CodeBase = "classfiledirectoryname" The directory (or path) of the Java Class file will be executed, if you do not provide this property, the directory of the JSP file using the Name = "instanceename" The name of this bean or applet instance will be called in JSP. Archive = "uritoarchive, ..." Some pathnames separated by commas, these path names are used to pre-install some of the Class to use, which increases the performance of the applet. Align = "bottom | TOP | Middle | Left | RIGHT" Graphics, objects, and applets, have the following values: Bottom TOP Middle Left Right Height = "DisplayPixels" width = "displaypixels" Applet or bean will display the long width value, this value is a number, the unit is pixel. Hspace = "Leftrightpixels" vSpace = "Topbottompixels" Applet or bean is displayed on the screen, the space you need to leave up and down, the unit is pixel. Jreversion = "JreversionNumber | 1.1" Applet or bean runs the version of Java Runtime Environment (JRE) required. The default is 1.1. nspluginurl = "Urltoplugin" Netscape Navigator users can use the download address of JRE, this value is a standard URL, such as http://www.aspcn.com/jsp IEPLUGINURL = "URLTOPLUGIN" The download address of the JRE that IE can use, this value is a standard URL, such as http://www.aspcn.com/jsp You need to send parameters or parameter values to Applets or Beans. A text is used for the Java plug-in to display to the user when the plugin is booted and the Applet or Bean cannot be, then the browser will have an error message pop-up. Set the attribute value in the bean. JSP syntax Name = "beaninstancename" { Property = "*" | Property = "PropertyName" [param = "parametername"] | Property = "PropertyName" Value = "{string | <% = expression%>}" } /> example Description / R You can use a variety of ways to use Match the attributes in the bean by the specified value input by the user by all values input by the user (in the Request object in parameter storage), match the specified value input by the user. Use an expression when running to match the properties of the bean Each method of setting attribute values has its specific syntax, below we will explain Property and its usage Name = "beaninstancename" Represents the name of the bean instance created in Property = "*" Store all values for the user in the JSP input to match the properties in the bean. The name of the attribute in the bean must match the parameter name in the Request object. The parameter values transmitted from the customer to the player are generally character types, which must be converted to other types in the bean, and the type of bea property and their conversion method are listed in the table below. Transform strings into other types of methods. Property type method Boolean or Boolean Java.lang.Boolean.Valueof (String) Byte or byte Java.lang.byte.valueof (String) Char or Character Java.lang.Character.Valueof (String) Double or DOUBLE Java.lang.double.valueof (String) Integer or Integer Java.lang.integer.Valueof (String) Float or float Java.lang.float.Valueof (String) Long or long Java.lang.long.Valueof (String) If there is an empty value in the parameter value of the Request object, the corresponding bean property will not set any values. Similarly, if there is an attribute in the bean without the corresponding request parameter value, then this property is also not set. Property = "PropertyName" [param = "parametername"] Use a parameter value in the Request to specify an attribute value in the bean. In this syntax, Property specifies the property name of the bean, and param specifies the parameter name in the request. If the bean property is different from the name of the request parameter, you must specify Property and Param if they are the same name, then you just need to indicate that Property is fine. If the value is empty (or not initialized), the corresponding bean property is not set. Property = "PropertyName" Value = "{string | <% = expression%>}" Use the specified value to set the bean property. This value can be a string or an expression. If this string, it will be converted to the type of the bean property (see the above table). If it is an expression, then its type must be consistent with the type of attribute value to be set. If the parameter value is empty, the corresponding attribute value will not be set. Also, you can't use Param and Value in a skill If you use Property = "*", then bean's properties are not necessary to sort in the order in the HTML form. Create a bean instance and specify its name and scope. JSP syntax ID = "BeanInstanceName" Scope = "Page | Request | Session | Application" { Class = "package.class" | TYPE = "package.class" | Class = "package.class" type = "package.class" | Beanname = "{package.class | <% = expression%>}" type = "package.class" } { /> | | > Other Elements jsp: usebean> } example jsp: usebean> Description / R For positioning or examples of beans, Try to locate a bean by a given name and scope. Reference variables for this bean object are named in the name you specify. If this bean is found, this reference will be stored in this variable. If you also specify a type, this bean is also set to the corresponding type. If this bean is not found, it will be sampled from the class you specified and this reference is stored in a new variable. If the name of this class represents a template, then this bean is sampled by java.beans.beans.instantiate. If Properties and usage ID = "BeanInstanceName" Confirm the parameters of the bean in the range you define, you can use this variable name to distinguish between different beans in the later program. This variable name is sensitive to case, and must meet the scripting language you are using, in Java Programming Language, this rule has been written in the Java Language specification. If this bean is already created in other The range of beans exists and the valid range of the ID variable name. The default is Page, the following is a detailed description: Page - You can use Beans in the JSP file containing Request - You use bean in any JSP file that performs the same request until the page is executed to respond to another file or go to another file. You can use the Request object to access bean, such as request.getattribute (BeanInstanceName) Session - From Creating a bean, you can use the bean in any JSP file using the same session. This bean exists within the entire session survival cycle, any JSP file in sharing this session can use the same bean. Note that you create BEAN's JSP file must specify session = true in the <% @ Page%> instruction Application - From Creating a bean, you can use the bean in any JSP file using the same Application. This bean exists within the entire Application Licheng period, any JSP file in sharing this Application can use the same bean. Class = "package.class" Use the new keyword and the Class constructor from a class from a class. This class cannot be abstract, there must be a public, no parameter constructor. This package is subject to case. TYPE = "package.class" If this bean already exists in the specified range, write this bean a new database type. If you don't use Class or BeanName to specify Type, Bean will not be sample. Package and Class's name, case sensitive. Beanname = "{package.class | <% = expression%>}" type = "package.class" Use the java.beans.beans.instantiate method to sample a bean from a Class or continuous template while specifying the type of the bean. Beanname can be Package and Class or an expression, it will pass the value of Beans.instantiate.TUPE can be the same as beans. Package and Class name are case sensitive.