JSP 2.2规范 对jsp:useBean的解释

JavaServer Pages 2.2 Specification (JSP 2.2 规范对jsp:useBean的解释)

一个jsp:useBean动作创建一个与id相同且与在给定作用域内定义的java程序实例对象相关的脚本变量

当jsp:useBean动作被用于一个脚本页面或一个脚本上下文时并没有创建java脚本变量,只是创建了一个EL变量

这个jsp:useBean动作非常灵活,其确切的语义取决于给定的属性。本质上jsp:useBean试图通过id在给定的作用域内
查找已存在的对象,如果这个对象没有找到那么它将尝试使用其他属性创建该对象

在没有提供class或beanName属性的情况下,jsp:useBean动作也能使用type属性给定义在任何jsp页面或servlet中的对象命名

最少提供type和class中的其中之一,但class和beanName属性同时使用则无效。如果提供的是type和class属性,
那么class属性必须是可实例化的类型(即它不能是接口和抽象类),否则将得到个转换错误

JavaServer Pages 2.2 Specification
CHAPTER JSP.5
JSP.5.1

A jsp:useBean action associates an instance of a Java programming language object defined within a given scope and available with a given id with a newly declared scripting variable of the same id.
When a action is used in an scriptless page, or in an scriptless context (as in the body of an action so indicated), there are no Java scripting variables created but instead an EL variable is created.
The jsp:useBean action is quite flexible; its exact semantics depends on the attributes given. The basic semantic tries to find an existing object using id and scope. If the object is not found it will attempt to create the object using the other attributes.
It is also possible to use this action to give a local name to an object defined elsewhere, as in another JSP page or in a servlet. This can be done by using the type attribute and not providing class or beanName attributes.
At least one of type and class must be present, and it is not valid to provide both class and beanName. If type and class are present, class must be assignable to type (in the Java platform sense). For it not to be assignable is a translationtime error.

你可能感兴趣的:(jsp:useBean)