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:
Describe this annotation and HTML is very like, that is, it can be seen in "View Source Code". The only thing is different, you can use expressions in this comment (Example 2). This expression is Unexvited, different from the page, you can use various expressions, as long as it is legal. More, see the expression =========================================== ============== Hide Note Write in the JSP program, but not sent to customers. JSP syntax <% - Comment -%> example: <% @ page language = "java"%>
A Comment Test
A Test of Comments <% - this Comment Will NOT BE Visible In The Page Source -%> Description Characters with hidden comment tags are 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 appear in the customer's browser, nor does it see in the source code in <% - %> You can write a comment statement, but you can't use "-%>", if you do not use "-%>". ============== ============================================================================================================================================================================================================= Declare the legal variable and method JSP syntax <%! Declaration; [declaration;] ...%> <%! Int 1, b, c;%> <%! INT i = 0;%> <%! INT A, B, C;% > <%! Circle a = new circle (2.0);%> Description Declare that the variables and methods you want to use in the JSP program. You must also do this, or you will make mistakes. You can declare multiple variables and methods in one time, as long as you end, you will be legal in Java. When you declare methods or variables, please pay attention to some of the following rules: The statement must be ";" end (Scriptlet has the same rules, but the expression is different). You can use it directly in <% @ Page%> Contains the already declared variables and methods, 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 element. ============================================================================================================================================================================================================= ================ Expression contains a JSP syntax expression JSP syntax <% = expression%>
<% = map.size ()%>
<% = number>. Description expression element represents an expression defined in the scripting language, which is automatically converted into a string after running, then inserted into this expression in the JSP file display. Because the value of this expression has been converted into a string, you can insert this expression in a line of text (the form and ASP is exactly the same). Please remember the following points when you use an expression in JSP: You can't Use a semicolon (";") as an end of the expression. But the same expression is used in a scripTlet! View Scriptlet This expression element can include any expression that is valid in Java Language Specification. Sometimes expressions can also be attribute values for other JSP elements. One expression can become complicated, it may be made of one or more Expression composition, the order of these expressions is from left to right. ============================================================================================================================================================================================================= ================ Scriptlet contains a valid block. JSP syntax <% code fragment%> example <% string name = null; if (Request.GetParameter ("name") == NULL) {%> <% @ include file = "error.html"%> <%} else {foo.setname ("name"); if (foo.getname (). EqualsignoreCase. INTEGRA ")) Name =" acura "; if (" Acura ") {%> Description A scripTlet can include multiple JSP statements, methods, variables, expressions because of Scriptlet, we can do the following things : The declaration of variables or methods that will be used (refer to declaration). Write a JSP expression (reference expression). Use any implicit objects and any use
Declared objects written JSP statements (if you are using Java language, these statements must follow Java Language Specification,) any text, HTML tag, JSP element must be in the ScriptleTlet When JSP receives the customer's request, Scriptle is a scriptlet Executed, if the scriptlet has the content displayed, these displayed content is present in the OUT object. ============================================================================================================================================================================================================= ==================================================================================================================== "RelativeURL"%> example include.jsp: an include test
THE CURRENT DATE AND TIME ARE <% @ include file = "DATE.JSP"%> Date.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 <% @ include%> Directive will insert a file containing text or code when JSP compile When you use <% @ include%> command, 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 where you are <% @ include%>.
Once the included file is executed, the process of the primary JSP file will be recovered, continue to perform the next line. This is included in the HTML file, JSP file, text file, or just a Java code, but you have to pay attention to this included The file cannot be used in the file, because this will affect the same tag in the original JSP file, so sometimes it will result in errors. Some <% @ include%> The behavior of the command is based on special JSP compilation conditions For example, this file is included in all customers and must be valid, or it has secure restrictions. If this containment file is changed, the JSP file containing this file will be recompiled: file = "relativeurl" The path name containing files is generally referring to relative paths, no port, protocol, and domain name, as follows: "Error.jsp" / templates / online.html "/ beans / calendar.jsp" If this path "/" Begins, then this path is primarily the up and down relationship path of the JSP application. If the path is starting with a file name or directory name, then this path is the current path of the JSP file in use. ======== ============================================================================================================================================================================================================= ======== Page instruction defines global properties in the JSP file. JSP syntax <% @ Page [language = "java"] [extens = "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 = "5K B "Autoflush =" false "%> <% @ Page ErrorPage =" Error.jsp "%>
Description <% @ Page%> The instruction applies to the entire JSP page, and also includes static include files. However, <% @ page%> The instruction does not act on dynamic include files, such as you can use multiple <% @ Page%> instructions in a page, but there is only one, but there is an exception, then It is the import property. Because the Import property and the Import statement in Java are almost (refer to Java Language), you can use this property a few times. Whether you put <% @ Page%> instructions in JSP files, its role range It is the 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. Attribute language = "java" declares the type of scripting language, temporarily only "java" extends = " Package.class "Moves full names for Java Class when JSP compile, but cautiously use it, it limits the compiletability of JSP. Import =" {package.class / package. *}, ... " A list of imported Java packages, these packages act on blocks, expressions, and declarations. The following packages have been imported at JSP compile, so you don't need to specify again: java.lans. * Javax.servlet.jsp. * Javax.servlet.http. * Session = "true / false "Set whether the customer needs http session. (Soced with ASP, it should be unfamiliar with it) if it is true, then Session is useful. If it has false, then you can't use the session object, and define scope = session.
element. Such use can cause errors. The default is true. Buffer = "none / 8kb / sizekb" The size of the buffer is used by the OUT object to handle the executionful JSP to the client browser. The default is 8KB autoflush = "true / false" setting If the buffer overflows, if it is necessary to force the output, 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 set the buffer to none, you can't set autoflush to false. IsthReadsafe = "true / false" Set whether the JSP file can be used multithreaded. The default value is true, that is, JSP can handle a request for multiple users at the same time. If set to false, a JSP can only process a request info = "text" once in execution JSP will be joined JSP In, you can retrieve it using the servlet.getServletInfo method. ErrorPage = "RelativeURL" Sets the JSP file that handles exception events. iSerrorPage = "true / false" Set whether this page is an error page, if you are set to true, you can use the Exception object. ContentType = "MimeType [; charset = characterset]" / "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. =============================== ============================================= Taglib command defines a prefix of a label library and its custom label. JSP syntax <% @ Taglib URI = "uritotaglibrary" prefix = "tagprefix"%> example <% @ taglib URI = "http://www.jspcentral.com/tags" prefix = "public"%>.
Description <% @ taglib%> The directive declares that this JSP file uses a custom label, and references the label library, also specifies the prefix of their label. The custom label here contains tags and elements. Because the JSP file can be converted to XML, it is important to understand the connection between the label and elements. The label is just a mark that is raised in a sense, which is part of the JSP element. The JSP element is part of the JSP syntax, and the start tag and end tag are the same as XML. Elements can also contain other texts, tags, and elements. For example, a JSP: Plugin element has
Start tagging
End marks, can also have
with
Element. You must use <% @ taglib%> instruction before using the custom label, and you can use multiple times in a page, but the prefix can only use the attribute uri = "uritotaglibrary" uniform Resource Identifier (URI) according to the label The prefix is unique to the custom label, the URI can be the following: Uniform Resource Locator (URL), is defined by RFC 2396, view http://www.hut.fi/u/jkorpela/rfc/2396/ Full.html Uniform Resource Name (URN), defined by RFC 2396 PREFC 2396 prefix = "tagprefix" prefixed before the custom label, for example, in the public, if this is not writtenless, then this is not legal. Please do not use JSP, JSPX, Java, Javax, Servlet, Sun, and SUNW as your prefix ======================================================================================================================================================================================================================= ==============================================================================================================================================
Redirect an HTML file, JSP file, or a block. JSP syntax
"} /> OR
"}"
example
description
The label passes an REQUEST object that contains the user request from a JSP file to another.
The code below the label will not be executed. You can send parameters and values to the target file, in this example, the parameters we passed are username, the value is Scott, if you use it
If the label, the target file must be a dynamic file to handle parameters. If you use non-buffered output, then use
Be careful when you are. If you are using
Previously, the JSP file already had data, then the file execution will be wrong. Attributes Page = "{relativeURL / <% = expression%>}" This is an expression or a string to explain the file you want to orientally or URL. 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 in a JSP file.
. Name Specify parameter name, value specifies parameter value. ========================================= ============================== Get the attribute value of the bean, used to display the JSP syntax in the page
example
Calendar of
Describe this
The element will get the property value of the bean, and can be used or displayed in the JSP page. Use
Before you must use
Create it.
Elements have some restrictions: you can't use
To retrieve an attribute that has been index you can use with the JavaBeans component
However, it cannot be used with Enterprise Bean. The name of the attribute name = "beaninstancename" bean, by
Specifies the property name of the bean specified by Property = "PropertyName". Tip: In the JSP reference in Sun, if you use
To retrieve the value is null, then NullPointersException will appear, and if you use a block or expression to search the value, NULL (empty) appears on the browser. ========== ============================================================================================================================================================================================================= ==========
Contains a static or dynamic file. JSP syntax
oral
Examples
description
Elements allow you to include dynamic files and static, which are different from the results of the files. If the file is just a static file, this includes adding the contents of the included file to the JSP file, and if this file is dynamically, then this containing file will be executed by the JSP compiler (this is similar to the ASP 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 the need.
Can handle these two files at the same time, so you don't need to include this file is dynamic or static. If this containing file is dynamic, then you can use
Parameter names and parameter values are also passed. Attributes Page = "{relativeurl / <% = expression%>}" parameter is a relative path, or represents a relative path expression. Flush = "true" Here you must use flush = "true", you can't use false value Default value of false
The clause allows you to pass one or more parameters to dynamic files. You can use multiple in a page.
To deliver multiple parameters. =============================================== ====================== Performed an applet or bean, there is a possible call to download a Java plugin for execution it. JSP syntax
[
[
]
] [
Text Message for User
]
example
Unable to load applet
description
The element is used to play or display an object in the browser (typical is applet and bean), and this display requires the Java plugin of the browser. When the JSP file is compiled, when sending to the browser,
Elements will be replaced according to the version of the browser
Or elements. Note that HTML 4.0 is used for HTML 3.2. Generally,
The element will specify the object is applet or bean, and the name of the class is also specified, and there is location, and it will also specify where to download this Java plugin. Specifically: Property Type = "bean / applet". The type of plugin object to be executed, you must specify this bean or applet, because this property does not have a default. Code = "classfilename" will be executed by Java plugin The name of Java Class must end with .class. This file must exist in the directory specified by the CodeBase property. CodeBase = "ClassFileDirectoryName" will be executed by the Java Class file directory (or path), if you do not provide this property, then use
The directory of the JSP file will be used. Name = "instanceName" This bean or the name of the Applet instance, it will call other places in JSP. Archive = "uritoarchive, ..." Some path names separate from comma, These pathnames are used to pre-install some of the Class to use, which increases the performance of Applet. Align = "bottom / top / middle / left / right" graphic, object, Applet location, have the following values: bottom Top Middle Left Right Height = "DisplayPixels" width = "displaypixels" Applet or bean will display the length of the value, this value is a number, the unit is pixel. Hspace = "Leftrightpixels" vSpace = "Topbottompixels" applet or bean is displayed at the screen, The space required to leave, the unit is pixel. Jreversion = "JreversionNumber / 1.1" Applet or bean runs the required Java Runtime Environment (JRE) version. The default is 1.1. NspluginURL = "URLTOPLUGIN" Netscape Navigator users The download address of the JRE that can be used, this value is a standard URL, such as http://www.aspcn.com/jsp iepluginarch = "URLTOPLUGIN" IE user can use the JRE download address, 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.
Text Message for User
A piece of text is used for the Java plugin to display to the user when the plugin is booting and the applet or bean cannot, then the browser will have an error message pop-up. ================ ============================================================================================================================================================================================================= =======
Set the attribute value in the bean. JSP syntax
example
description
The element uses the setter method given by the bean, sets one or more attribute values in the bean. You must use this element before you use this element.
Declare this bean. Because
with
It is associated, and the name of the Bean instance they use should also match (that is,
The value of the Name of Name should be
The value of the ID is the same), you can use a variety of methods to use
To set the property value: Match the properties in the bean by the specified value entered by the user input by the user entered all values (required as parameter storage), matching the specified value specified in the bean in runtime using an expression when running. To match the properties of the bean, each of the settings attribute values have their specific syntax. Here we will talk about the name of the reality and its usage name = "beaninstancename" indicates the name of the bean instance already created. Property = "* "Store all values of users in JSP input to match the properties in the bean. The name of the attribute in the bean is consistent with the parameter name in the Request object. The parameter value transmitted from the customer is generally the character type, which must be converted into other types in the bean. The type of bean property is listed in the table below and their conversion method. 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.valueof (String) If there is a nougant 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 attribute is also not set. Property = "PropertyName" [param = "parametername"] Use a parameter value in the request to specify bean A property value. In this syntax, Property specifies the bean's attribute name. PARAM specifies the parameter name in the request. If the bean property is different from the name of the request parameter, then you must specify Property and Param, if they are the same name, then you just need to specify Property will be. If the value is empty (or not initialized), the corresponding bean attribute is not set. Property = "PropertyName" value = "{string / <% = express%>}" uses the specified value to set 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. In addition, you can't be in one
Simultaneously use PARAM and VALUE tips 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
/> Other Elements
} Example
description
Used to position or sample a JavaBeans component.
First try to locate a bean instance, if this bean does not exist, then
An example will be made from a class or template. For positioning or examples of a bean,
The following steps are performed, the order is as follows: 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 the type, this bean is also set to the corresponding type. If this bean is not found, it will be sampled from the class you specify and this reference is stored in a new variable. If the name of this class represents a template, this bean is sampled by java.beans.beans.instantiate. If
Already sample (not positioning) bean,
with
There is element, then the code will be executed.
The main body of the element is usually included
Elements, used to set the attribute value of the bean. As mentioned above,
The body is only in
Example Bean will be executed, if this bean already exists,
Ability to locate it, then the contents in the body will not function and use id = "beaninstancename" to confirm the bean variable in the range you define, you can use this variable name in the later program to distinguish different beans 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 in any
Create, then the value of this ID must be consistent with the original ID value. Scope = "Page / Request / Session / Application" bean exists and the valid range of the ID variable name. The default is Page, the following is a detailed description: Page - you can include