JSP syntax detailed http://www.aspcn.com provides www.aspcn.com December 25, 2001 15:40 --------------------- -------------------------------------------------- ------- JSP grammar ] -> Example 1 generated in the client's HTML source code The same data above: Example 2 -> Displayed in the client's HTML source code as: Description This annotation and HTML are very like, that is, it can look at "View Source Code" The only thing is that you can use expressions in this comment (see shown in Example 2). This expression is not different, different from the page, you can use various 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 <% -%>: <% @ page language = "java"%>
statement
Declaring the legal variables and methods in the JSP program
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 want to use 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 ";" ends (Scriptle has the same rules, but the expression is different). You can directly use the declared variables and methods that have been included in <% @ Page%>, do not need to be re-needed A declaration. 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> <% = number> b>. Description 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 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 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 A scripTlet can include multiple JSP statements, methods, variables, expressions
Because Scriptlet, we can do the following things:
Declare the variables or methods that will be used (refer to the declaration). Write a JSP expression (reference expression). Writing a JSP statement with any hidden objects and any objects expressed with
Include instruction
Contains a static file in the JSP while parsing the JSP statement in this file.
JSP syntax <% @ include "%> example include.jsp:
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 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. The path name is generally referring to the relative path, does not need to 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 <% @ Page%> Instructions Contemporary to the entire JSP page, also include static Contains files. But <% @ page%> The instruction does not act on dynamic containing files, such as
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.
Attribute language = "java" declares the type of scripting language, which can only use "java"
Extends = "package.class" indicates the full name of Java Class, but it is carefully used when JSP compiles, but it will use it, which limits the compiletability of JSP.
Import = "{package.class | package. *}, ..." Requires the imported Java package list, which acts 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, you 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 the
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 accident. Error happening. If you set the buffer to none, then you can't set autoflush to false.
Isthreadsafe = "true | false" settings if 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, you can use the servlet.getServletInfo method to retrieve.
ErrorPage = "RelativeURL" Sets the JSP file that handles exception events.
iSerrorPage = "true | false" Set whether this page is an error page, and you can use the Exception object if you are set to True.
ContentType = "MIMETYPE [; Charset = CharacterSet" | "text / html; charset = ISO-8859-1" Set 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
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
Attributes Page = "{relativeURL | <% = express%>}" This is an expression or a string to explain the file or URL you will oriented. This file can be a JSP, block, or other capable of handling Request Object files (such as ASP, CGI, PHP).
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
You can't use
Property = "PropertyName" attribute name specified by the bean.
Tip: In the JSP reference in Sun, if you use
Contains a static or dynamic file.
JSP syntax
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%>}" 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
jsp: plugin>
Example Unable to load applet p> jsp: Fallback> jsp: plugin> Description When the JSP file is compiled, when sending to the browser, the In general, the Properties Type = "bean | applet". The type of plugin object that will be executed, you must specify this bean or applet because this property has no default. Code = "classfilename" will be the name of the Java Class executed by the Java plugin, must end with .CLASS. This file must exist in the directory specified by the CodeBase property. CodeBase = "classfileDirectoryName" will be executed Directory (or path) of the Java class file, if you do not provide this property, the directory of the JSP file using Archive = "uriToarchive, ..." Some path names separate from comma, which are used to pre-install some Class to use, which increases the performance of the applet. Align = "Bottom | Top | Middle | LEFT | Right" graphics, objects, and 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 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 required Java Runtime Environment (JRE) version. The default is 1.1. NSPLUGINURL = "URLTOPLUGIN" Netscape Navigator users can use the JRE download address, this value is a standard URL, such as http://www.aspcn.com/jsp IEPLUGINURL = "URLTOPLUGIN" IE users can use the JRE download address, this value is a standard URL, such as http://www.aspcn.com/jsp Set the attribute value in the bean. JSP syntax Match the attribute specified in the bean by the specified value of the bean by the user input by all values entered by the user (in the Request object as a parameter storage), match the specified value specified by the user to match the attribute of the bean to match the properties of the bean. Method for setting attribute values has its specific syntax, below we will explain Attributes and their usage name = "beaninstancename" indicates the name of the bean instance created in Property = "*" stores all values input by the user in the JSP, used 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 will 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 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 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 Description Try to locate a bean by a given name and scope. Reference variables for this bean object are named with 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 Properties and Usage ID = "BeanInstanceName" confirms the bean variable in the range you define, you can use this variable name in the later program to distinguish between 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 created in other Scope = "Page | Request | Session | Application" bean exists and the valid range of ID variable names. The default is Page, the following is a detailed description: Page - You can use Beans in the JSP file containing 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 - Start with the creation bean, you can use the bean in any JSP file using the same Application. This bean exists within the entire Application Licheng, any JSP file in sharing this Application can use the same bean. Class = "package .class "uses the new keyword and the Class constructor from a class in a class. This class cannot be abstract, there must be a public, no parameter constructor. This package name is case sensitive. 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" uses java.beans.beans.instantiate methods to sample a bean from a Class or continuous template while specifying the type of 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.