Sending string arrays to a servlet on another server

hi guys

i'm trying to send string arrays from one servlet to another servlet without using the request.setAttribute function as i eventually want to send data to servlet located on another server. is that possible?

for example:
where each variable is an array.

please help..thanks in advance

so far i get grabbled response when i do a system.out.println on the receiving so:

Who is Participating?
objectsConnect With a Mentor Commented:
> ../Order/NewOrderServlet?orderID="+orderID+"&purchaseID="+purchaseID+"&customerID="+customerID+"&productID="+productID+"&sellingPrice="+sellingPrice+"&quantity="+quantity
where each variable is an array.

instead you would use:


how is the recieving servlet expecting the data or are you also implementing that.
why don't you use
To send the data out

OutputStream out = connection.getOutputStream() ;
out.write(paramBuf) ;
and this to get the data in

Object o = null;
ObjectInputStream ois = new ObjectInputStream (connection.getInputStream());
o = ois.readObject();

psicokhelAuthor Commented:
hi im sorry..can you elaborate a little more?

do u mean that i create a URLConnection to the remote servlet and do a getOutPutStream?

Sorry i don't get it, thanks for your time, copyPasteGhost!

and im trying to send invidiual arrays.


String[] orderIDs, String[] productIDs, int[] quantity, float[] sellingPrice

there is no way to forward a request to a servlet on another server right? otherwise i can just use request.Set/GetAttribute and get it all over and done with. sigh.

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

you can't do this..

and then send your String[]s like that

String mypath = ""; //path to your jsp page on which ever server you want.
String[] myStringArray = new String[3];

URL url = new URL(myPath);
         HttpURLConnection conn = (HttpURLConnection)url.openConnection();
         conn.setRequestProperty("Content-type", "application/octet-stream");
         OutputStream os = conn.getOutputStream();
         ObjectOutputStream out = new ObjectOutputStream(os);


and then you have to catch it on your jsp page and then do what you want with it
Make sense?
catch meaning receive..
sorry for the confusing terminalogy
psicokhelAuthor Commented:
okay i'll try it later to see if it works.

does this mean that I can only send one array? or can i do several out.writeObject? I'll give it a try. Thanks, will be back to accept answer if it works
I guess if you want to send it in one shot you can maybe build a vector of String[] and then just send the vector..
there are ways around that
psicokhelAuthor Commented:

ouch .. that would be very tedious if there were, say 20 orders ..

on the receiving servlet i use:

String[] orderID;
orderID = (String[])  request.getParameterValues("orderID");

but its not working as posted above..
>  that would be very tedious if there were, say 20 orders ..

you'd just build the query string in a loop.
psicokhelAuthor Commented:
ya..i figured. doesn't seem very elegant though..

and copypasteghost..does your sample work with servlet? as in the destintation url is a servlet.
i tried implementing your code but it seems that it did not even load the destination servlet

thanks to both of you for your time. i'll have to use objects method if there aren't any better solutions soon..running out of time =(
>i'm trying to send string arrays
>say 20 orders ..
objects' solution is good as long as the query string doesn't get too long.
Ghost's  solution could send a List of Lists or some other suitable data structure.       rrz
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.