R
Ramon F Herrera
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 should use a loop (?) to read a record/line at
a time with 'readLine()', or is all the data perhaps stored
in a buffer?
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);
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 should use a loop (?) to read a record/line at
a time with 'readLine()', or is all the data perhaps stored
in a buffer?
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);