Board index » jbuilder » Multi-line reading from applet?

Multi-line reading from applet?


2003-07-17 04:30:03 PM
jbuilder18
I just began using a technique to get a single value
from the web server to my applet via CGI-BIN.
Please see relevant code below.
With this technique -I was given a chunk of code, I don't
even understand its behavior completely- I can retrieve
one value from the server. Now I would like to retrieve
multi-line data, such as that coming from a SQL statement which
will be used to populate my applet's menus.
So, how should I retrieve this cursor-like, or stream data?
I suppose I need to put the "s = d.readLine()" statement inside
a loop, but what loop variable shoould I use??
TIA,
-Ramon F. Herrera
-----------------------------------------------------------------------
URL url;
URLConnection urlConn = null;
DataOutputStream dos;
DataInputStream dis;
InputStream is;
url = prepareServerCommand(Id, true);
try {
urlConn = url.openConnection();
} catch (IOException ex) {
}
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
String s = null;
try {
dos = new DataOutputStream(urlConn.getOutputStream());
String message = "NEW_ITEM=1";
dos.writeBytes(message);
dos.flush();
dos.close();
is = url.openStream();
BufferedReader d = new BufferedReader(new InputStreamReader(is));
s = d.readLine(); // s now contain the value that I need
d.close();
} catch (IOException ex1) {
}
jButton1.setText("Number of Items:");
jTextField1.setText(s);
done = 1;
return (done);
 
 

Re:Multi-line reading from applet?

Ramon,
You can build an object containing your data in an array or vector for
instance and then use object serialisation to pass the object from servlet
to applet.
Look at the link in the post underneath this (Database and Applets for more
information).
It's pretty similar to what you are doing already. You just have to remember
that the object you are sending and any objects that it contains must
implement the Serializable interface for it to work.
Hope this helps.
Arth
"Ramon F Herrera" < XXXX@XXXXX.COM >wrote in message
Quote
I just began using a technique to get a single value
from the web server to my applet via CGI-BIN.
Please see relevant code below.

With this technique -I was given a chunk of code, I don't
even understand its behavior completely- I can retrieve
one value from the server. Now I would like to retrieve
multi-line data, such as that coming from a SQL statement which
will be used to populate my applet's menus.

So, how should I retrieve this cursor-like, or stream data?
I suppose I need to put the "s = d.readLine()" statement inside
a loop, but what loop variable shoould I use??

TIA,

-Ramon F. Herrera