JSP EL可以直接进行属性访问吗? [英] Can JSP EL do direct attribute access

查看:139
本文介绍了JSP EL可以直接进行属性访问吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这真的让我感到惊讶!我的JSP中有以下代码.

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

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

这段代码一直有效,直到我重构了SlideShow类并公开了所有属性并删除了getters/setter方法.因此在我看来,EL仅适用于getter,而不适用于直接属性访问.这是真的 ?有什么方法可以使它与直接属性一起使用,而不是通过getter进行操作?

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严格依赖Java Bean规范,因此它不能使用其他约定来访问属性值.

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

实际上,您可以阅读以下内容: StackOverflow EL标签说明

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

因此可以调用非getter方法(非属性),但只能从某些EL控件调用:

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

由于EL 2.2是Servlet 3.0/JSP 2.2(Tomcat 7,Glassfish 3,JBoss AS 6等)的一部分,因此有可能调用非getter方法,如果需要的话还可以使用参数.

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.

例如$ {bean.find(param.id)}与

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

public Something find(String id) {
    return someService.find(id);
}

这篇关于JSP EL可以直接进行属性访问吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆