Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP bean and parameter question

 
Tiya Khambadkone
Ranch Hand
Posts: 109
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my JSP I am setting the value inside a variable :
<c:set var="cover" value="${param.cover}" />

This value gets set properly. It is either acover, bcover or ccover

I want it use it in the same jsp like :

${mybean.acover.lib}
OR
${mybean.bcover.lib}
OR
${mybean.ccover.lib}

depending on the ${cover} value.

I want something like :
${mybean.${cover}.lib}

What is the correct syntax ?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${mybean[cover].lib}
 
Tiya Khambadkone
Ranch Hand
Posts: 109
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ParseException: Encountered " "[" "[ "" at line 1, column 16.
Was expecting:
<IDENTIFIER> ...
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I'm missing something, but why isn't it just

${mybean.cover.lib}

?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tiya Khambadkone wrote:ParseException: Encountered " "[" "[ "" at line 1, column 16.
Was expecting:
<IDENTIFIER> ...

Then you did something wrong. Post your code. Don't make us guess!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Maybe I'm missing something, but why isn't it just

${mybean.cover.lib} ?

That would assume the property cover is hard-coded, rather than a variable.

What you posted is equivalent to: ${mybean['cover'].lib}
 
Tiya Khambadkone
Ranch Hand
Posts: 109
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that does not work too...

looks like it tries to find a property name 'cover' inside myBean.java and then throws an exception as it does not find.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post. Your. Code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic