While trying to iterate a map in a javascript function by passing key as below:
<html> <head>
<script type="text/javascript">
function demo(tmp){
<c:forEach var="user" items="${usermap}">
<c:out value="${usermap.get(\"+'tmp'+\").name}"></c:out>
</c:forEach>
}
</script>
<title>Insert title here</title> </head>
<body>
<h1 onclick="demo('user1')">User VO</h1>
<c:forEach var="user" items="${usermap}">
Key: ${user.key} - Name: ${user.value.name} - Id: ${user.value.userid}<br/><br/>
</c:forEach>
</body> </html>
I am getting blank value. But when I hard code the value of key***user1***, it works.
Servlet Code protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub
//System.out.println("in servlet doGet:"+ ++count);
UserVO user1= new UserVO("Y","701");
UserVO user2= new UserVO("D","834");
hmap.put("user1", user1);
hmap.put("user2", user2);
//hmap.values()
request.setAttribute("usermap", hmap);
//response.sendRedirect("User.jsp");
RequestDispatcher view = request.getRequestDispatcher("User.jsp");
view.forward(request, response);
//response.getWriter().append("Served at: ").append(request.getContextPath());
}
Can somebody help me here?