java - jsp中 'class'和 'type'属性之间的差异

标签 java jsp javabeans

在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" />    

现在我的问题是 -

  1. 什么type在这里做什么?
  2. 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.

来源:Attributes and Usage of jsp:useBean action tag

关于java - jsp中 'class'和 'type'属性之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28970589/

相关文章:

java - 获取没有 Locale 常量的国家/地区的货币格式

java - 如何在 JSP 中迭代 map ?

java - 如何使用 jasper 报告在 java beans 中生成包含 3 个嵌套列表的表?

java - 为什么 Java Bean 必须是可序列化的?

java - 如何使用Lombok创建调用父类(super class)AllArgsConstructor的构造函数?

java - 无法在 Android WebView 中加载本地 HTML 文件

java - Tomcat 8 - 在 MySQL Workbench 中从每个 tomcat 实例中看到最多 8 个 MySQL 连接

java - 在 Java 线程中同步

java - JDWP 退出错误 JVMTI_ERROR_WRONG_PHASE(112)

java - 将 WAR 文件部署到远程服务器后出现错误(在本地机器上没有错误)