kamal
kamal

Reputation: 1193

show map data using jstl in jsp

MyServlet.java

LinkedHashMap<String, LinkedHashMap<String, MyObj>> lhm = 
                    new LinkedHashMap<String, LinkedHashMap<String, Bank>>();
LinkedHashMap<String, MyObj> lhmObj = new LinkedHashMap<String, Bank>();

lhmObj.put(arg1, arg2);
lhm.put(arg3, lhmObj);

request.setAttribute("Map", lhm);
getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);

index.jsp

<c:forEach items="${Map}" var="myMap">
  <c:out value="${myMap.key}"></c:out>
  <c:out value="${myMap.value}"></c:out>
</c:forEach>

I wrote this code and worked successfully but this showed:

ADD {213412=my.package.directory.MyObj@2e6d441d,
       213413=my.package.directory.MyObj@792e3bb}

I want to show the data which is in the MyObj. How to do it?

Upvotes: 0

Views: 1295

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 122006

Here <c:out value="${myMap.value}"></c:out>

Your ${myMap.value} returning another map i.e (LinkedHashMap<String, MyObj>)

So ,you need to do another loop in side with ${myMap.value}

Upvotes: 1

Related Questions