Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
只是想知道是否有一种方法可以在不创建自定义标记库的情况下从我的类中访问方法。
示例 我有一个提供 4 种方法的类:hasDisplay()、hasCreate()、hasDelete() 和 hasEdit()——它们都只返回一个布尔值。
从我的jsp我只想
<c:if test="{ar.hasEdit}"></c:if>
但这仅适用于 getter 和 setter 方法,对吗?
如果您不想编写自己的标签,您可以为提供“beanish”接口的对象提供装饰器。所以你用 isHasEdit() 包装 hasedit() 这样你可以保持你的 jsps 干净并且仍然使用所需的语法,但你最终会得到“脏”的包装器。
我会选择自定义标签库。没那么复杂。
正确,JSP EL 只能访问 bean 属性。其他任何东西都需要自定义标记库。这还不够好,但它就在那里。