java - "generalizes the tag object' s 存储”是什么意思?

标签 java jsp

谁能澄清一下Head First Servlets & JSP下面的行概括了标签对象的属性存储行的含义吗? (第 555 页):

One solution would be to put all of the attributes into a hashtable. This generalizes the tag object's storage of attributes, but what about all these setter methods? We can't get rid of them unless there's a way to tell the JSP engine to set the tag attributes using a generic interface.

提前致谢。

最佳答案

在此上下文中,“概括”意味着您可以编写一个函数或一小段代码来实现所有案例,而不是单独编写每个案例。我没有那本书,但看起来它取代了类似的东西:

 String attr1;
 String attr2;
 String attr3;

 Hashtable<String, String> attributes;

这是对存储的概括 - 代码旨在显示将字符串映射到字符串的通用哈希表 - 您将使用类似的东西

 attributes["attr1"] = "value";

其他代码的使用方式如下:

 attr1 = "value";

关于java - "generalizes the tag object' s 存储”是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1121529/

相关文章:

java - 从 JPA 中排除类中的字段

java - OnClickListener 内部的实现函数 - Android

eclipse - 没有为命名空间 [/] 和 Action 名称 [] 映射的 Action 与上下文路径 [/struts] 关联

jsp - 使用 JSTL 检查集合大小

java - 尝试通过JSP访问servlet中创建的bean

java - xtend 支持多个构造函数吗?

java - android.content.res.Resources$NotFoundException : File res/layout/action_menu_layout. 来自 xml 类型布局资源 ID #0x109001b 的 xml

java - 在 Java 中使用 smartcardio 在 Raspberry Pi 上使用多个 NFC ACR122U 设备

java - AXAX刷新JSP或Spring MVC页面的简单方法?

Java Ajax 显示进度