HashMap in JSP

Can we pass HashMap object from one page to another page in JSP?Advance Wishes!!!!
[96 byte] By [Daiesha] at [2007-11-27 7:05:04]
# 1

yes why not....

Store the HashMap Object as an attribute under the scope of Request/Session/Application and then navigate to the other page..

Just as an Example check the below code...

first.jsp:

======

<%

HashMap hm = model.getHashMap();

// use it when you are not invalidating the session before we redirect or forward to the next page

session.setAttribute("map",hm);

// could be used until or unless the request object is died example when page is being redirected

//request.setAttribute("map",hm);

--

--

--

%>

second.jsp:

=========

<%

HashMap hm = (HashMap) session.getAttribute("map");

--

--

--

%>

Hope that might help :)

REGARDS,

RaHuL

RahulSharnaa at 2007-7-12 18:56:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks buddy, without session any other way can we do that?advance wishes!!!!!
Daiesha at 2007-7-12 18:56:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
As explained by Rahul you can store the HashMap Object as an attribute under the scope of Request/Session/Application and then navigate to the other page..If u don't want to use session then use request.....
anurag_dasha at 2007-7-12 18:56:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
thanks for your information
Daiesha at 2007-7-12 18:56:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Just pointing out that request scope only lasts (funnily enough) for one request.

If you want to keep the hashmap alive over multiple JSP pages you need to keep it in session.

Another alternative would be to convert it to string put it into a hiddenfield on the JSP page, and then reconstruct it from string when it comes back as a request parameter. But using the session is easier.

evnafetsa at 2007-7-12 18:56:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...