File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes geting only l;ast vale from hashmap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "geting only l;ast vale from hashmap" Watch "geting only l;ast vale from hashmap" New topic
Author

geting only l;ast vale from hashmap

arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
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

Joined: Mar 09, 2005
Posts: 47
Have you tried using an iterator?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
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

Joined: Jul 08, 2005
Posts: 125
solved
arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: geting only l;ast vale from hashmap
 
Similar Threads
does html link provide
jsp standard actions or tags instead of scriplet
pageContext problem
Struts html:link problem
hash map getting null or only last value