Sending string arrays to a servlet on another server
5 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shaun_Lim
Posted On:   Sunday, May 2, 2004 08:05 AM

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

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

[F@5d391d

   <<Less

Re: Sending string arrays to a servlet on another server

Posted By:   shahram_pourdashti  
Posted On:   Thursday, May 6, 2004 07:17 AM

Alternatively, you can loop through the string arrays and put name/values pairs on the url. Use the same name for the members of each array. On the recieving servlet getParameterValues(java.lang.String name) will return you java.lang.String[] for each array name.

Re: Sending string arrays to a servlet on another server

Posted By:   Raj_Chandra  
Posted On:   Thursday, May 6, 2004 06:48 AM

Not sure whether you can send the arrays like that. Reason: the arrays are created in a heap and you will get only the references. One way you can do is taking that array and convert them into a single string by adding delimeters to each of them. Then at the receiving end, use StringTokenizer to split them and get back the array.

Eg.
value[0]="One";
value[1] = "Two";
value[2]="Three";

String str = value[0] + "|" + value[1] + "|" + value[2];

now you can send the str and at the receiving end, use StringTokenizer to get the array back. Roundabout way, but it works. One another way you can do is convert the array into XML, send the XML as a string and at the other end, using DOM/SAX, you can get back the strings.

Hope this helps.
Raj

Re: Sending string arrays to a servlet on another server

Posted By:   sushil_srivastava  
Posted On:   Thursday, May 6, 2004 02:33 AM

What you really need to grap the response on the target servlet is getParameter() and getParameterValues() function of the request.That will allow you to print the relevant values which you passed in the request.

Re: Sending string arrays to a servlet on another server

Posted By:   shahram_pourdashti  
Posted On:   Wednesday, May 5, 2004 01:49 PM

http doesn't know about java objects. You might have to serialize the array and post the data and then un-serialize into an array.

Re: Sending string arrays to a servlet on another server

Posted By:   tech_tech  
Posted On:   Monday, May 3, 2004 02:38 PM

looks like u r getting the data - the println statement of the whole array will give u the memory address of the strings.
try casting the array and then print one element at a time u will get it ...
send in the code for more detailed answer
About | Sitemap | Contact