Solved

passing an array and retrieving that array

Posted on 2003-11-06
9
554 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
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 20 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Apache-Tomcat Single Sign On with NTLM/Kerberos on Windows 2008R2 3 217
How to group array of objects ? 5 65
runtime exception 2 28
jsp login check 12 32
An article on effective troubleshooting
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

777 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