JSP syntax (7)

xiaoxiao2021-03-06  68

Create a bean instance and specify its name and scope.

JSP syntax

ID = "BeanInstanceName"

Scope = "Page | Session | Application"

{

Class = "package.class" |

TYPE = "package.class" |

Class = "package.class" type = "package.class" |

Beanname = "{package.class | <% = expression%>}" type = "package.class"

}

{

/> | |

> Other Elements

}

example

description

is used to position or sample a JavaBeans component. You will try to locate a bean instance if this bean does not exist, then is an example from a Class or template.

For positioning or examples of beans, will make the following steps, 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 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 has been sample (not locating), it has an element in and , then the code will be executed.

Elements typically contains elements for setting the properties of the bean. As mentioned above, the principal of is only executed when the sample bean is executed, if this bean already exists, can locate it, then the main body The content will not work

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 , the value of this ID must be consistent with the original ID value.

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 element, and all static include files in this file until the page performs a response to the client or go to another file.

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.

转载请注明原文地址:https://www.9cbs.com/read-92732.html

New Post(0)