Need help with applet interacting with CGI script.

Status
Not open for further replies.
I'm trynig to save some information to a file on my webserver but I'm having troubles. I found this link:
http://www.webdeveloper.com/java/java_jj_read_write.html
but it's not very thorough in it's description and don't know enough about CGI or perl. I have a script set up and running on the server, presumably it sits there and waits for an outside machine to send or recieve data from it.

I'm trying to implement all this from an applet on the client but I'm not entirely sure how. I believe im supposed to open a connection to the computer via the URL class but I'm unsure as to whether I should be pointing the applet to the address of the script (i.e http://www.whatever.com/cgi-bin/script.pl) or I should simply use the domain and the script will sort itself out.

Here's some code I've done

#!/usr/bin/perl
# wdwrite
# this is the CGI that will take the # applet info and write it to a file

open(OUT, "> /data.txt");
print "content-type: text/plain\n\n";

while (<> ) {
print OUT $_;
print $_;
}
close (OUT);
exit 0;


NB data.txt contains the data that I need.
And here is my java code that tries to access the script

DataInputStream data;
String line;
StringBuffer buf = new StringBuffer();
String s = "";
try
{
//URL myUrl = new URL(myurl);
URLConnection conn = myUrl.openConnection();
conn.connect();
System.out.println("Connection made...");
data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
while((line = data.readLine()) != null)
{
buf.append(line + "\n");
s = buf.toString();
}

}
catch(MalformedURLException e)
{
System.out.println("MalFormedURL Exception");
}
catch(IOException d)
{
System.out.println("Found an IO exception");
System.out.println(d.getMessage());
}

I really hope you can help.
 
Status
Not open for further replies.