This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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.
Joined: Dec 10, 2008
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.
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.
Joined: Dec 10, 2008
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..