• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in accessing the Map in c:forEach loop of JSTL

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I am using JSP2.0. i have created one simple application in which form gets submitted and servlet gets called which creates the map and place it inside the session scope and redirect the page to the new jsp page.I am deploying the application on the server jboss 4.0.2 -GA.

Here is the Directory Structure of my Web Application.

----------------------------------
Structure of my Web Application
----------------------------------

SCWCD
|
|
WEBCONTENT
| | |
| | |
| | JSP
| | |
| | |
| | index.jsp
| WEB-INF
| | |
| | |
| | classes
| | |
| | <compiled classes>
| lib
| |
| <All the libraries are here>
finalresults.jsp

-----------------
index.jsp
------------------

-------------------------
SimpleServlet.java
--------------------------

-------------------------
finalresults.jsp
--------------------------

Now the problem is that when i run this application and submit index.jsp form gets submitted and displays the following output.

---------
[Output]
---------
Displaying the key property first

displaying the Map values

Displaying the key property second

displaying the Map values
Displaying the value dhaval

-----------
[/output]
-----------

Problem is that why doesn't it displays any thing for the line on the jsp

<br/>displaying the Map values ${personmap["${item.key}"].name}

since the personmap is a map and i am passing the ${item.key} which contains the key of the map then it should display the value "dhaval" for the key "first" and value "ketan" for the key "second".


while in the last line it displays the value "dhaval" correctly.

can anybody tell me the reason for this ?

any kind of help would be appreciated.

Regards
Jinesh Parikh.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't nest ${} inside the map expression. try:
${personmap[item.key].name}

1) No ${}. JSP already knows it is in an expression context since you have ${} surrounding the map
2) No quotes. Quotes would signify a literal String. No quotes means variable expression.
3) You may be able to simplify with:
 
jinesh parikh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you steve for the answer.

Now it is working fine.

Currently I am reading "Head First Servlets and JSP" of oreilly publication.This book is also very good.

But if i want to read JSP and Servlet in more detail then
Could you please suggest any good book for reading JSP?

Regards
Jinesh Parikh.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jinesh,


I have heard good things about Head First Servlets and JSPs, but I can't recommend one myself for learning JSPs and Servlets. I haven't really read one - I learned the basics from Java EE Tutorial at Sun.

If you search this forum or one of JavaRanch's Books Discussion Forums you might find some better references.

Best of Luck,

Steve
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic