File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to reference a hash map value with a JSP variable as its key? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to reference a hash map value with a JSP variable as its key?" Watch "How to reference a hash map value with a JSP variable as its key?" New topic
Author

How to reference a hash map value with a JSP variable as its key?

Stan Lederer
Ranch Hand

Joined: Sep 24, 2012
Posts: 35
I've got a hash map entry in a JSP which I can display fine as ${current.collectionCode}.

I have a second hash map, ${collectionUrls}, from which I can extract, as an example, ${collectionUrls['XYZ']}

If ${current.collectionCode} = XYZ, how can I get ${collectionUrls[${current.collectionCode}]}?

I'm stumped.

Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Not

There's too much markup there. You just need ${} to indicate that the contents is an EL expression, no more. So
Stan Lederer
Ranch Hand

Joined: Sep 24, 2012
Posts: 35
Paul Clapham wrote:Not

There's too much markup there. You just need ${} to indicate that the contents is an EL expression, no more. So

Paul, that worked beautifully. Thank you.

Now, would you help me to understand why I don't need ${} around the variable when it's used in this context but I do need it when the variable is used by itself? Is there a rule that you should only ever use one set of ${} in an expression and anything inside of it that doesn't look like a literal is assumed to be a variable?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Like I said. You put ${} around an EL expression. Not in it, but around it. That's all. It doesn't matter whether the expression is a single variable or a complex calculation.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

${} is not a "fetch" operator. It's merely a delimiter around an entire EL expression.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to reference a hash map value with a JSP variable as its key?