This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

geting only l;ast vale from hashmap

 
arjun rampal
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am getting only last value from hashmap
codes are below

jsp code

<bean efine id="a" name="b" property="c"/>
<bean efine id="e" name="b" property="d"/>
<%
java.util.HashMap params = new java.util.HashMap();
params.put("a",a);
params.put("b",b);
session.setAttribute("paramsName", params);
%>



action classs code
Map paramsName = new HashMap();


paramsName=(HashMap)session.getAttribute("paramsName");
 
Divya Guttikonda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried using an iterator?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to put two values in your HashMap, you will have to change your code as follows:

<%
java.util.HashMap params = new java.util.HashMap();
params.put("a",a);
params.put("b",e);
session.setAttribute("paramsName", params);
%>

The name of the second variable you create is e, not b.
 
arjun rampal
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am getting only last value from hashmap
codes are below.

Then I used iterator and getting
Required string is null or empty



jsp code

<bean efine id="a" name="b" property="c"/>
<bean efine id="e" name="b" property="d"/>
<%
java.util.HashMap params = new java.util.HashMap();
params.put("a",a);
params.put("b",e);
session.setAttribute("paramsName", params);
%>



action classs code
Map paramsName = new HashMap();


paramsName=(HashMap)session.getAttribute("paramsName");
if (paramsName!=null)
{Iterator pIter = paramsName.keySet().iterator();
while(pIter.hasNext()){
a=(String)pIter.next();}
 
arjun rampal
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
solved
 
arjun rampal
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
solution
<jsp:useBean id="params" class="java.util.HashMap" scope="session" />
<bean efine id="a" name="b" property="c"/>
<bean efine id="d" name="e" property="f"/>
<%
params.put("c",a);
params.put("d",d);
session.setAttribute("paramsName", params);
%>

in action class use
request.getParameter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic