在jsp中我发现 -
<jsp:useBean id="user" class="com.test.UserDetails" />
我的意思是(如果我错了,请纠正我)-如果 UserDetails
实例已经存在,那么它将被分配一个 id user
如果不存在则一个新的 UserDetails
对象已创建并将被分配 id user
。
但在一些非常罕见的情况下,我发现了以下<jsp:useBean>
与 type
-
<jsp:useBean id="account" type="com.test.Account" />
现在我的问题是 -
- 什么
type
在这里做什么? type
之间有什么区别和class
?
提前致谢。
最佳答案
class:
instantiates the specified bean class (i.e. creates an object of the bean class) but it must have no-arg or no constructor and must not be abstract.
和
type:
provides the bean a data type if the bean already exists in the scope. It is mainly used with class or beanName attribute. If you use it without class or beanName, no bean is instantiated.
关于java - jsp中 'class'和 'type'属性之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28970589/