国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
關(guān)于jsp:useBean的不同寫法

<jsp:useBean>

Locates or instantiates a Bean with a specific name and scope.

JSP Syntax

<jsp:useBean		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 tags </jsp:useBean>	}

Examples

<jsp:useBean id="cart" scope="session" class="session.Carts" /><jsp:setProperty name="cart" property="*" /><jsp:useBean id="checking" scope="session" class="bank.Checking" ><jsp:setProperty name="checking" property="balance" value="0.0" /></jsp:useBean>

Description

The <jsp:useBean> tag attempts to locates a Bean, or if the Bean does not exist, instantiates it from a class or serialized template. To locate or instantiate the Bean, <jsp:useBean> takes the following steps, in this order:

  1. Attempts to locate a Bean with the scope and name you specify.
  2. Defines an object reference variable with the name you specify.
  3. If it finds the Bean, stores a reference to it in the variable. If you specified type, gives the Bean that type.
  4. If it does not find the Bean, instantiates it from the class you specify, storing a reference to it in the new variable. If the class name represents a serialized template, the Bean is instantiated by java.beans.Beans.instantiate.
  5. If it has instantiated (rather than located) the Bean, and if it has body tags (between <jsp:useBean> and </jsp:useBean>), executes the body tags.

The body of a <jsp:useBean> tag often contains a <jsp:setProperty> tag that defines property values in the object. As described in Step 5, the body tags are only processed if <jsp:useBean> instantiates the Bean. If the Bean already exists and <jsp:useBean> locates it, the body tags have no effect.

In JSP 1.0, <jsp:useBean> works with JavaBeans components, but not with enterprise beans. If you want to use enterprise beans, you can write a JSP file that constructs a JavaBean component, and have the JavaBean component call the enterprise bean.

Attributes and Usage

  • id="beanInstanceName"

    Names a variable that identifies the Bean in the scope you specify. You can use the variable name in expressions or scriptlets in the same JSP file.

    The name is case sensitive and must conform to the naming conventions of the page scripting language (if you use the Java programming language, the conventions in the Java Language Specification). If the Bean has already been created by another <jsp:useBean> tag, the value of id must match the value of id used in the original <jsp:useBean> tag.

  • scope="page|request|session|application"

    Defines a scope in which the Bean exists and the variable named in id is available. The default value is page.

  • class="package.class"

    Instantiates a Bean from a class, using the new keyword and the class constructor. The class must not be abstract and must have a public, no-argument constructor. The package and class name are case sensitive.

  • class="package.class" type="package.class"

    Instantiates a Bean from a class, using the new keyword and the class constructor, and gives the Bean the type you specify in type. The class you specify in class must not be abstract and must have a public, no-argument constructor. The package and class names you use with both class and type are case sensitive.

    The value of type can be the same as class, a superclass of class, or an interface implemented by class.

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

    Instantiates a Bean from either a class or a serialized template, using the java.beans.Beans.instantiate method, and gives the Bean the type specified in type. Beans.instantiate checks whether a name represents a class or a serialized template. If the Bean is a serialized template, Beans.instantiate reads the serialized form (with a name like package.class.ser) using a class loader. For more information, see the JavaBeans API Specification.

    The value of beanName is either a package and class name or an Expression that evaluates to a package and class name, and is passed to Beans.instantiate. The value of type is a package and class name. The value of type can be the same as beanName, a superclass of beanName, or an interface implemented by beanName.

    With both beanName and type, the package and class names are case sensitive.

  • type="package.class"

    If the Bean already exists in the specified scope, gives the Bean the type you specify. If you use type without class or beanName, no Bean is instantiated. The package and class name are case sensitive.

 
1.
<jsp:usebean id="cart" scope="session" class="session.carts" />
<jsp:setproperty name="cart" property="*" />

此類寫法表示設(shè)置屬性的動作總是執(zhí)行

2.
<jsp:usebean id="cart" scope="session" class="session.carts" >
<jsp:setproperty name="cart" property="*" />
</jsp:userbean>

此類寫法表示設(shè)置屬性的動作在變量JavaBean對象不存在時執(zhí)行

Java code
index.jsp<%@ page language="java" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Test the UserBean Tag</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"></head><body><form action="another.jsp"><jsp:useBean id="plainBean" class="com.PlainBean" scope="session"/><jsp:setProperty name="plainBean" property="name" value="John1"/><font color="blue"><jsp:getProperty name="plainBean" property="name"/></font><jsp:useBean id="anotherBean" class="com.AnotherBean" scope="session"><jsp:setProperty name="anotherBean" property="name" value="John2"/><font color="blue"><jsp:getProperty name="anotherBean" property="name"/></font></jsp:useBean><input type="submit" ></form></body></html>another.jsp:<%@ page language="java" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Test the UserBean Tag</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"></head><body><jsp:useBean id="plainBean" class="com.PlainBean" scope="session"/><jsp:setProperty name="plainBean" property="name" value="Tom"/><font color="blue"><jsp:getProperty name="plainBean" property="name"/></font><jsp:useBean id="anotherBean" class="com.AnotherBean" scope="session"><jsp:setProperty name="anotherBean" property="name" value="Tom"/><font color="blue"><jsp:getProperty name="anotherBean" property="name"/></font></jsp:useBean></body></html>
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
java研究館--jsp+javabean循序漸進教程
JavaBean學習專題
Java Web筆記 – JavaBean的使用 JavaBean的范圍 與Java代碼的交互
JavaBean
JSP useBean詳解
JavaBean組件程序設(shè)計(1)
更多類似文章 >>
生活服務(wù)
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服