JSP study notes
JSP has five types of elements: annotations, template elements, pace elements, instruction elements, and action elements.
1. Template elements refer to JSP static HTML or XML content. Mainly the framework and structure of the webpage.
2. Note There are three categories: html / xml annotations, hidden comments, Java annotations in Scriptlets.
Grammar: ] ->
<% - comment -%>
3. The script elements mainly include declaration, expression (Expression), Scriptlets.
Declared grammar format: <%! Variable Declaration
Menthod Declaration (paramtype param ...%>
In the statement, the method or constant to be encapsulated in the class, and the variables and methods after the declaration can be used in any place in JSP.
Expression grammar format: <% = Some Java Expression%>
The expression calculates its value during the JSP request processing phase, and the resulting result is converted into a string and a template data.
Scriptlets grammar format: <% java code statements%>
ScriptleTs is the Java code executed when the page processing request in JSP.
4. The instruction element has three page instructions, include instructions, Taglib instructions.
The syntax format of the page instruction:
<% page [language = "java"] [import = "{package.class | package. *}, ..."] [contentty = "type; charSet = charset"] [session = "true | false" [buffer = "None | 8KB | SIZEKB"] [Autoflush = "True | Flase"] [isthreadsafe = "true | false"] [info = "text"] [errorpage = "relativeurl"] [ISERRPAGE = "true | false"] [ Extends = "package.class"] [iSelignored = "true | false"] [PageEncoding = "peinfo"]%>
Property Description Default Example Language Definition The language "java" language = "java" mGuage = "java" import into the language ignition ignore IMPORT = "java.io. *, Java.util.hashtable" session Specify whether this page is involved in an HTTP session True session = "true" buffer setting buffer mode and buffer numerical value is not less than 8KB buffer = "64kb" AutoFLASH Setup Buffer full time to refresh true autoflush = "true" info set JSP page information, available servlet.getServletInfo () to get the default ignore Info = "Test Page" ISERRORPAGE Set whether the current page is an errorPage target false isrrorPage = "false" errorPage defined this page The page is called when the page is called by default ignore errorpage = "erroe.jsp" isthreadsage setup JSP files can be multi-thread use True isThreadSafe = "true" contentType pageEncoding MIME types defined character encoding and character encoding JSP page response tYPE = text / html cHARSET = iso8859-1 contenType = "text / html charset = bg2312" pageEncoding JSP pages = iso8859-1 pageEncoding = "GB
2312 "ISELIGNORED Develops EL to ignore the default value with web.xml settings iSelignored =" true "
The PAGE directive defines the Global Properties of JSP, which acts on true page.
The syntax format of the include instruction:
<% @ include file = "relativeURL"%>
<% @ 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.
The Taglib instruction allows the developer to customize the label, adding a reuse of the code.
5. Action elements
JSP: Param operations provide additional information (parameters of dynamic files) for other tags in the form of "name-value".
jsp: incrude>
JSP: The include operation allows for a static or dynamic file to be included within the request time. The object being included only has access to the JSpWriter object, which cannot set the head or cookie. If the page output is buffered, the refresh of the buffer is superior to the included refresh.
oral
jsp: Forward>
JSP: The Forward operation will be redirected to another JSP, servlet, or static resource file. You can transfer parameters and values to your target file, which is often used to log in, permission verification page. If you use a non-buffered output, you should be careful when using
Where: Name = BeanInstanceName is a must-select property, its value of bean, is introduced by JSP: UseBean. Property = "*" This is a shortcut to set the bean property. In the bean, the name, the type of the property must match the parameter name in the Request object name. Property = "PropertyName" uses a parameter in the Request to specify an attribute in the bean. Property Specifies the name of the bean, and the bean property and the name of the request parameter should be the same.
Property = "PropertyName" param = "parameterName" uses this method when the name of the bean property is different. Param specifies the parameter name of the Request object. Property = "PropertyName" value = "PropertyValue" Value is an optional attribute that uses the specified value to set the properties of the bean.
You cannot use Param and Value at the same time, they are just different ways to set the value of the bean property. If there is a null value or a property in the parameter of the Request object, there is no corresponding request parameter value, then the corresponding bean property will not be set.
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 Java.lang.Boolean.Valueof (String) .booleanValue ()
Boolean Java.lang.Boolean.Valueof (String)
Byte java.lang.byte.valueof (String) .betevalue ()
Byte java.lang.byte.valueof (String)
Char java.lang.Character.Valueof (String) .Charvalue ()
Character java.lang.Character.Valueof (String)
Double java.lang.double.valueof (String) .doublevalue ()
Double java.lang.double.valueof (string)
Integer java.lang.integer.Valueof (string) INTVALUE ()
Integer java.lang.integer.Valueof (String)
Float java.lang.float.Valueof (String) floatvalue ()
Float java.lang.float.Valueof (String)
Long java.lang.long.Valueof (String) longue ()
Long java.lang.long.valueof (string)
Used to access a bean property, transform it into a string, and then send it to the output stream. If the property is an object, the toString () method will be called. It cannot be used to retrieve an attribute that has been indexed.
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 with the name you specify. If this bean is found, this reference will be stored in this variable. If you also specify a type, then this bean is also set to the corresponding type. If this bean is not found, it will instance from the class you specify and save this reference to a new variable. If the name of this class represents a template, this bean is instantiated 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 in the later program to distinguish between the variable names for large-sink, must meet the scripting language you use, in Java Programming Among the Language, this rule has been stated in the Java Language specification. If this bean is created in other
Scope = "Page | Session | Application"
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.getaTRibute (BeanInstanceName) Session starting from creating a bean, you can use Bean in any JSP file using the same session. This bean exists within the entire Session survival period, any in sharing This session's JSP file can use the same bean. Note that in the <% @ Page%> command in the JSP file you created, you must specify session = true
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"
BEAN's class path and class name. This class cannot be abstract, there must be a public, no parameter constructor. Package and Class's name, case sensitive.
TYPE = "package.class"
TYPE can be a class itself or a parent class or a class of interface. If you don't use Class or BeanName to specify Type, Bean will not be instantiated. Package and Class's name, case sensitive.
Beanname = "{package.class | <% = expression%>}" type = "package.class"
Use the java.beans.beans.instantiate method to instantiate 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. Class and Beanname cannot be used at the same time.
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"]> [ [ 3.2. Generally, 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" IE users 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. 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.