Can JSP EL do direct attribute access

2019-02-25 07:08发布

This really surprised me ! I have the following code in my JSP.

<c:param name="title" value="${slideShow.title}" />

This code was working till I refactored the SlideShow class and made all attributes public and removed getters/setters. So it seems to me that EL works only with getter and not direct attribute access. Is this true ? Is there any way to get it to work with direct attributes instead of going through getters ?

标签: jsp el
1条回答
仙女界的扛把子
2楼-- · 2019-02-25 07:45

JSP EL relies strictly on Java Bean specification, so it cannot use other conventions to access property values.

Actually, you can read about this is StackOverflow EL tag description

So it's possible to invoke non-getter methods(not attributes) but only from certain EL vesion:

Since EL 2.2, which is maintained as part of Servlet 3.0 / JSP 2.2 (Tomcat 7, Glassfish 3, JBoss AS 6, etc), it's possible to invoke non-getter methods, if necessary with arguments.

E.g. ${bean.find(param.id)} with

public Something find(String id) {
    return someService.find(id);
}
查看更多
登录 后发表回答