Solved

Sending string arrays to a servlet on another server

Posted on 2004-05-02
11
534 Views
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:
../Order/NewOrderServlet?orderID="+orderID+"&purchaseID="+purchaseID+"&customerID="+customerID+"&productID="+productID+"&sellingPrice="+sellingPrice+"&quantity="+quantity
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 servlet..like so:

[Ljava.lang.String;@f30494
[Ljava.lang.String;@b1cc87
[Ljava.lang.String;@eaf40c
[Ljava.lang.String;@13c6641
[I@50a649
0
Comment
Question by:psicokhel
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 10971960
why don't you use
To send the data out

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

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

Ghost
0
 

Author Comment

by:psicokhel
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.

eg:

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.

0
 
LVL 13

Expert Comment

by:copyPasteGhost
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.setDoOutput(true);
         conn.setRequestMethod("POST");
         conn.setRequestProperty("Content-type", "application/octet-stream");
         OutputStream os = conn.getOutputStream();
         ObjectOutputStream out = new ObjectOutputStream(os);

out.writeObject(myStringArray);
         out.flush();
         out.close();

and then you have to catch it on your jsp page and then do what you want with it
Make sense?
Ghost
0
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 10972401
catch meaning receive..
sorry for the confusing terminalogy
Ghost
0
 

Author Comment

by:psicokhel
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:copyPasteGhost
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
Ghost
0
 
LVL 92

Accepted Solution

by:
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:

../Order/NewOrderServlet?orderID0="+orderID[0]+"&purchaseID0="+purchaseID[0]+"&customerID0="+customerID[0]+"&productID0="+productID[0]+"&sellingPrice0="+sellingPrice[0]+"&quantity0="+quantity[0]+"&orderID1="+orderID[1]+"&purchaseID1="+purchaseID[1].......


how is the recieving servlet expecting the data or are you also implementing that.
0
 

Author Comment

by:psicokhel
ID: 10974105
objects:

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

Expert Comment

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

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

Author Comment

by:psicokhel
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 =(
0
 
LVL 27

Expert Comment

by:rrz
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

18 Experts available now in Live!

Get 1:1 Help Now