This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Applets and the fly likes how can i transfer multiple values from applet to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "how can i transfer multiple values from applet to servlet" Watch "how can i transfer multiple values from applet to servlet" New topic
Author

how can i transfer multiple values from applet to servlet

A Bhat
Greenhorn

Joined: May 05, 2009
Posts: 7
Hi,
I want to know how can i transfer multiple values from applet to servlet.Am successful in transferring single value but don't know about multiple.Can i transfer array of string this way from applet?:

String ar[]={fname,uname};
URLConnection con = getServletConnection1();
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);
oos.writeObject(ar);
oos.flush();
oos.close();

BUT HOW ABOUT in server side:

I have this over there:in servlet(This will definitely not work.This servlet code i made for accepting single string value)
What are the changes i should do in servlet code for accepting my string array from applet ?

InputStream in = request.getInputStream();
ObjectInputStream inputFromApplet = new ObjectInputStream(in);
String answer = (String) inputFromApplet.readObject();
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18712
    
    8

If you can send a String that way, then you can send an array of Strings just the same way. Of course you would have to cast the result to a String array in your servlet...
A Bhat
Greenhorn

Joined: May 05, 2009
Posts: 7
will it be this in servlet?

String[] ar = (String[]) inputFromApplet.readObject();

If so,then how to read the values ar[0] for 1st value
ar[1] for next??

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how can i transfer multiple values from applet to servlet