Solved

passing an array and retrieving that array

Posted on 2003-11-06
9
553 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
Comment Utility
<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
Comment Utility
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
Comment Utility
i need to know: are u inserting all the parameters into a db?
0
 
LVL 15

Expert Comment

by:jimmack
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Accepted Solution

by:
mrishmawy earned 20 total points
Comment Utility
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
Comment Utility
>>>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
Comment Utility
Sorry yes.

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

Author Comment

by:tizay
Comment Utility
thanks a lot mrishmawy
0
 

Expert Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
In this article, I will show you HOW TO: Create your first Windows Virtual Machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, the Windows OS we will install is Windows Server 2016.
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now