Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I access a getter that has a parameter using JSTL or JSP 2.0 EL?

I want to access something like this:

public FieldInfo getFieldInfo(String fieldName) {
 ....
}

I could access this in Struts by using mapped properties but don't know if it is possible in JSTL or JSP 2.0.

I tried everything but is not working.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
487 views
Welcome To Ask or Share your Answers For Others

1 Answer

Passing method arguments in EL is only by EL spec supported in EL 2.2. EL 2.2 is by default shipped in Servlet 3.0 / JSP 2.2 containers. So if you're using a Servlet 3.0 container (Tomcat 7, Glassfish 3, JBoss 6, etc) and your web.xml is declared conform Servlet 3.0 spec, then you should be able to access it as follows

${bean.getFieldInfo('fieldName')}

Since you explicitly mentioned JSP 2.0, which is part of the old Servlet 2.4 spec, I assume that there's no room for upgrading. Your best bet is to replace the method by

public Map<String, FieldInfo> getFieldInfo() {
    // ...
}

so that you can access it as follows

${bean.fieldInfo.fieldName}

or

${bean.fieldInfo['fieldName']}

or

${bean.fieldInfo[otherBean.fieldName]}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...