Results 1 to 6 of 6
- 07-27-2010, 11:10 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 85
- Rep Power
- 0
Getting values from the map using jstl
Hi all,
Below is the code that I am working. I have a list as a key and a string and integer as values. The problem I am having is displaying the values of the map.
This is the output I getJava Code:<%@ page language="java" contentType="text/html" %> <%@ page import="java.util.*" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% // Create an ArrayList with test data List list = new ArrayList(); String[] arr={"name1","name2"}; list.add(arr); Map author1 = new HashMap(); author1.put(list, "A"); author1.put(list, new Integer(1)); //author1.put("list",list); pageContext.setAttribute("authors", author1); %> <html> <head> <title>Search result: Authors</title> </head> <body bgcolor="white"> <table> <TH>Name</th> <TH>Id</th> <TH>List</TH> <tr> <c:forEach var="entry" items="${authors}"> <c:forEach var="value" items="${entry.key}"> <c:forEach var="hvalue" items="${value}"> <TR> <TD>${entry.value}</TD> <c:if test="${!empty value}"> <TD>${hvalue}<br></TD> </c:if> </TR> </c:forEach> </c:forEach> </c:forEach> </tr> </table> </body> </html>
The output that I am expecting isJava Code:Name Id List 1 name1 1 name2
I am desperately in need of help. Can someone help me pleaseJava Code:Name Id List A 1 name1 A 1 name2
Thanks in Advance
- 07-28-2010, 09:34 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
A List as a key?
That really doesn't sound right...
Anyway, yoiu are using the same list object as your key for both things you are adding isn, resulting in the 'A' being overwritten by the '1'. So the only thing that you list is mapped to is the Integer '1', which is why you see the output you see.
Now, because I can't think of any reason to use a List as a key (key's are usually ids or Strings or enums, occasionally beans) I suspect your concept is wrong. What is it you're trying to do?
- 07-28-2010, 05:58 PM #3
Member
- Join Date
- Jun 2008
- Posts
- 85
- Rep Power
- 0
Thanks to Tolls for the reply. Thanks for pointing out, yes it was overridding. Anyway I solved the problem.
- 12-06-2011, 08:06 AM #4
Member
- Join Date
- Dec 2011
- Posts
- 5
- Rep Power
- 0
Re: Getting values from the map using jstl
hiiii Ms.Ranjan
i am facing the same problem....
so please tell me how this problem get resolve....
Thanks in advance..
- 12-06-2011, 09:44 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Getting values from the map using jstl
Maybe if you post your code and problem we might be able to solve it, but if it's the exact same problem then I explain what the trouble is in my post (including a lot of typos, it seems).
- 12-06-2011, 12:01 PM #6
Member
- Join Date
- Dec 2011
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Displaying array values in jstl page
By keshaba in forum Advanced JavaReplies: 0Last Post: 04-23-2010, 10:00 AM -
Jstl
By prakashkadakol in forum New To JavaReplies: 10Last Post: 01-13-2010, 07:17 PM -
HashMap contains all values but doesn't show all values
By xcallmejudasx in forum New To JavaReplies: 3Last Post: 05-10-2009, 11:35 PM -
Retaining DB values as well as Dynamically generated Values.. Help Needed !
By rajivjha in forum Advanced JavaReplies: 0Last Post: 05-22-2008, 10:53 AM -
Accessing boolean Values of another values in one class.
By a_iyer20 in forum Advanced JavaReplies: 4Last Post: 04-15-2008, 01:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks