This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Sending an Array to a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sending an Array to a Servlet" Watch "Sending an Array to a Servlet" New topic
Author

Sending an Array to a Servlet

Gayathri Neti
Greenhorn

Joined: Mar 08, 2002
Posts: 25
Hi,
I have a standalone client which invokes a Servlet.
I want to send an INTEGER ARRAY as a parameter to the Servlet. Can I do that?
If so, can anybody show me how??
Thanks
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hey
Try using streams. either ByteArrayOutput or ObjectOutput ....
From client I guess you are making URLConnection to the servlet. So, once you have the URLConnection object do connection.writeObject(); and on the servlet side do request.readObject(); look on google for this kind of URLConnection examples..
Regards
Maulin
Gayathri Neti
Greenhorn

Joined: Mar 08, 2002
Posts: 25
If I were passing the INTEGER ARRAY alone that might have worked fine.
I am passing 4 parameters. One of them is an INTEGER ARRAY.
Here is the code that I have:
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12758
    
    5
Like Maulin said, you could do this with object serialization. Look at the API for java.io.ObjectOutputStream and ObjectInputStream. Arrays of primitives and Strings are automatically Serializable as are Collections.
Bill
 
jQuery in Action, 2nd edition
 
subject: Sending an Array to a Servlet
 
Similar Threads
How i write in a servlet response an javascript array?
How to retrieve data from database, using servlet or a jsp?
Passing Variables to JSP
sending a Collection from JSP to Servlet
returning an array from servlet responce