Results 1 to 6 of 6
  1. #1
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default 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.

    Java 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>
    This is the output I get
    Java Code:
    Name   Id   List 
    
            1    name1
            1    name2
    The output that I am expecting is
    Java Code:
    Name   Id   List 
    
    A      1      name1
     
    A      1      name2
    I am desperately in need of help. Can someone help me please
    Thanks in Advance

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,746
    Rep Power
    19

    Default

    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?

  3. #3
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default

    Thanks to Tolls for the reply. Thanks for pointing out, yes it was overridding. Anyway I solved the problem.

  4. #4
    gopal026 is offline Member
    Join Date
    Dec 2011
    Posts
    5
    Rep Power
    0

    Default 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..

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,746
    Rep Power
    19

    Default 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).

  6. #6
    gopal026 is offline Member
    Join Date
    Dec 2011
    Posts
    5
    Rep Power
    0

    Default Re: Getting values from the map using jstl

    thanks it get resolved.

Similar Threads

  1. Displaying array values in jstl page
    By keshaba in forum Advanced Java
    Replies: 0
    Last Post: 04-23-2010, 10:00 AM
  2. Jstl
    By prakashkadakol in forum New To Java
    Replies: 10
    Last Post: 01-13-2010, 07:17 PM
  3. HashMap contains all values but doesn't show all values
    By xcallmejudasx in forum New To Java
    Replies: 3
    Last Post: 05-10-2009, 11:35 PM
  4. Replies: 0
    Last Post: 05-22-2008, 10:53 AM
  5. Replies: 4
    Last Post: 04-15-2008, 01:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •