Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

passing an array and retrieving that array

Posted on 2003-11-06
9
Medium Priority
?
564 Views
Last Modified: 2010-04-01
i already have values in my array. the problem is how can i pass it to another page and how will i retrieve it from that page.
 e.g. i have an array arr[]
how will i pass it and then retrieve it.thanks. a code will be much appreciated.

can i use this?
<input type="hidden" name="darray" value="arr">

and then get it in another page like this:
String[] myarray = request.getParameterValues("darray");

thanks in advance.
0
Comment
Question by:tizay
9 Comments
 
LVL 3

Expert Comment

by:applekanna
ID: 9698675
<input type="hidden" name="darray" value="1">
<input type="hidden" name="darray" value="2">
<input type="hidden" name="darray" value="3">
<input type="hidden" name="darray" value="4">

and get it as

String[] myarray = request.getParameterValues("darray");
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9698682
I am not sure if they will arrive in the same order if you are very particular about that.

Can you also explain what you need to send across so that we can see if there is a better way of doing it.
Hope this helps

Cheers!
0
 
LVL 1

Expert Comment

by:yapsing
ID: 9699134
i need to know: are u inserting all the parameters into a db?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:jimmack
ID: 9702011
If your "arr" is in a JSP, and you want this to be available on another page in one session (eg. if the data is to follow the user to the next page), then just store it in a session variable:

Source page
-----------------

<%
session.setAttribute("arr", arr);
%>

Target page
-----------------
<%
String[] arr = session.getAttribute("arr");
%>
0
 

Accepted Solution

by:
mrishmawy earned 80 total points
ID: 9702221
you can use:

<%
  for (int i = 0; i < arr.length; i++) {
%>
<input type="hidden" name="darray" value="<%= arr[i] %>">
<%
  }
%>

and then get it in another page like this:
String[] myarray = request.getParameterValues("darray");
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9703464
>>>Target page
-----------------
<%
String[] arr = session.getAttribute("arr");
%>

Just a clarification..
Dont we need to do a type cast ?How do you type cast a String arrary?
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9703504
Sorry yes.

String[] arr = (String[])session.getAttribute("arr");
0
 

Author Comment

by:tizay
ID: 9712262
thanks a lot mrishmawy
0
 

Expert Comment

by:paragagarwal
ID: 9712401
Simply keeep this array in Session and then retrieve it in other page
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Ranking ecommerce websites is a vital process. You need to have a strong SEO (Search Engine Optimization) strategy. If you don’t have one, you are losing out on brand impressions, clicks and sales. Check this guide on how to improve website traffic …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question