Sending string arrays to a servlet on another server

Posted on 2004-05-02
Last Modified: 2010-04-01
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:

Question by:psicokhel
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
LVL 13

Expert Comment

ID: 10971960
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();


Author Comment

ID: 10972351
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.

LVL 13

Expert Comment

ID: 10972399
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?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 13

Expert Comment

ID: 10972401
catch meaning receive..
sorry for the confusing terminalogy

Author Comment

ID: 10973791
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
LVL 13

Expert Comment

ID: 10973799
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
LVL 92

Accepted Solution

objects earned 125 total points
ID: 10973975
> ../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.

Author Comment

ID: 10974105

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..
LVL 92

Expert Comment

ID: 10974121
>  that would be very tedious if there were, say 20 orders ..

you'd just build the query string in a loop.

Author Comment

ID: 10974279
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 =(
LVL 27

Expert Comment

ID: 10974329
>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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Export JSON response data to Excel in IE9 3 97
java.util.concurrent.locks in java 3 209
print map entry 34 80
Drop down list show all elements but disabled for selection 6 61
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

752 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