• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to Set HashMap in request attribute using JSTL Tag

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Can you tell me how to set HashMap in request attribute using JSTL tag.. I am able to set HashMap in scriptlet and Iterate successfully, But when i try to set HashMap in request attribute using JSTL tag. I am getting the following error

 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you trying to do this in the first place? The JSTL and EL are meant to replace scriptlets, not work with them.

Tasks like setting maps up as scoped variables for use in the JSP is the job of the controller, not the JSP itself.
 
ShaikSalam Bashoeb
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I am working on very big project. I need to prepare one HashMap in jsp and set it again in request attribute, so that I can use that hashmap for remaining page of the jsp...
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why bother? Since you're hard-coding the values into the JSP to being with, why not just use those values directly in the HTML rather than going through the overhead of the Map? You're introducing a lot of complexity that isn't necessary.

If this is just an example and the values are not hard-coded, why isn't this being done in the controller?

Or, if you insist on doing it this way (not recommended), just uncomment the setAttribute() call and forget using the JSTL for this -- working with scripting variables is not what the JSTL was meant for. It's like using a nail file to comb your hair.
 
ShaikSalam Bashoeb
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I completely agree with your comments that we should not mix both scriptlet and JSTL But my intension was to ask that in JSTL there is


which is used to set the Attribute that we will do it from JSP page,
I also need to set one Attribute of HashMap that is why i asked , is there any way to set HashMap from JSP page using JSTL.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not if the Map is only available as a scripting variable. Scripting variables are invisible to the JSTL as, again, they are not intended to be used in concert.

JSP Rule #1: if it's hard to do on a JSP page with the JSTL/EL, there's a good chance that it's not something that you should be doing in a JSP in the first place.

If you are going to use scriptlets to create the Map on the page (still a futile exercise, in my opinion), then use scriptlets to create the scoped variable. Don't try to shoe-horn the wrong tool into the mix.
 
ShaikSalam Bashoeb
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear Bibeault for your quick responses and accurate.

I have understood that if we want to create Map and set in a request scope as a attribute then we should scriptlet.
NO way to do with JSTL..

Thanks again...
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, in modern web apps, nothing should be done in scriptlets. But if you are going to use them (not recommended), don't try to mix them with the JSTL and EL. They do not mix well.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic