I'm trying to connect a Java applet to a cgi script. The two things I want to do are reading from the script and then writing to the script. The reading part works fine. The part I'm having a problem with is the writing part.
Here's the function in Java where I write to the script:
public void writeFile() {
try {
String myurl = "script address" ;
URL url = new URL( myurl );
URLConnection connection = url.openConnection();
connection.setDoOutput( true );
PrintStream outStream = new PrintStream( connection.getOutputStream() );
StringBuffer send=new StringBuffer();
send.append(username).append("&").append(startTime).append("&").append(endTime).append("&");
for (int i=0;i<stats.length;i++) {
if (stats(sub(i)) { // only writing it this way because of anandtech italics formatting
send.append("1");
}
else {
send.append("0");
}
if (i<4) {
send.append("&");
}
}
outStream.println(send.toString());
outStream.close();
System.out.println(send.toString());
}
catch ( MalformedURLException mex ) {
System.err.println( "MalformedURLException: " + mex );
}
catch ( IOException ioe ) {
System.err.println( "IOException: " + ioe );
}
}
I'm sure that the string I want is correct because I print it to the console after closing the outStream and it looks fine.
Here's the CGI script, written in perl:
#!/usr/bin/perl
print "content-type: text/plain\n\n";
$input=<STDIN>;
$counter=0;
foreach (split(/&/,$input)) {
if ($counter==0) {
if ($_ eq "thisisnotausername12345") {
exit 0;
}
open(FILE,">>$_.profile");
}
else {
print FILE $_,"\n";
}
$counter++;
}
close (FILE);
exit 0;
All I want it to do is read the line of input from the Java applet, parse it, open the file using the first parsed string, and then write the rest to the file. I am quite certain that the perl script works ok. I copied the string outputted to the java console and then ran the script manually with the string as the input and it worked as I wanted. It doesn't seem like the java applet is connecting to the script correctly....
Anyone see anything wrong here?
Here's the function in Java where I write to the script:
public void writeFile() {
try {
String myurl = "script address" ;
URL url = new URL( myurl );
URLConnection connection = url.openConnection();
connection.setDoOutput( true );
PrintStream outStream = new PrintStream( connection.getOutputStream() );
StringBuffer send=new StringBuffer();
send.append(username).append("&").append(startTime).append("&").append(endTime).append("&");
for (int i=0;i<stats.length;i++) {
if (stats(sub(i)) { // only writing it this way because of anandtech italics formatting
send.append("1");
}
else {
send.append("0");
}
if (i<4) {
send.append("&");
}
}
outStream.println(send.toString());
outStream.close();
System.out.println(send.toString());
}
catch ( MalformedURLException mex ) {
System.err.println( "MalformedURLException: " + mex );
}
catch ( IOException ioe ) {
System.err.println( "IOException: " + ioe );
}
}
I'm sure that the string I want is correct because I print it to the console after closing the outStream and it looks fine.
Here's the CGI script, written in perl:
#!/usr/bin/perl
print "content-type: text/plain\n\n";
$input=<STDIN>;
$counter=0;
foreach (split(/&/,$input)) {
if ($counter==0) {
if ($_ eq "thisisnotausername12345") {
exit 0;
}
open(FILE,">>$_.profile");
}
else {
print FILE $_,"\n";
}
$counter++;
}
close (FILE);
exit 0;
All I want it to do is read the line of input from the Java applet, parse it, open the file using the first parsed string, and then write the rest to the file. I am quite certain that the perl script works ok. I copied the string outputted to the java console and then ran the script manually with the string as the input and it worked as I wanted. It doesn't seem like the java applet is connecting to the script correctly....
Anyone see anything wrong here?
