How to retrieve streams via CGI?

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top