Switching the page displayed - CGI called by a Java applet
by Steven Fletcher · in Technical Issues · 07/25/2004 (6:42 am) · 1 replies
I have an applet that posts to a CGI program.
The CGI program creates a file based upon the input and stores it on the server. This part is fine.
But it also displays the data with the print command. This does not appear. It appears when I call the CGI program from a form, but not when I call it from an applet.
Here is the CGI script minus a couple functions that should be irrellevant:
It's like that last print command just isn't working. The page just keeps displaying the applet instead of displaying what's supposed to be printed.
What I would really like to do is send the browser to the page that is created on the server. Unfortunately, I don't know how to do this with CGI. I do know how to do this with Javascript, but I don't want to add Javascript to this mess unless I have to - there's already too much room for bugs to crop up as it is.
There is another issue that doesn't matter unless it is somehow causing this problem. Here is my post-to-CGI Java code:
Notice that I open an InputStream at the end and never use it for anything. This is because the file doesn't get written to the server unless I open an InputStream to the CGI file. I do not know why this is. It doesn't matter though unless this is somehow related to the print command not working.
The CGI program creates a file based upon the input and stores it on the server. This part is fine.
But it also displays the data with the print command. This does not appear. It appears when I call the CGI program from a form, but not when I call it from an applet.
Here is the CGI script minus a couple functions that should be irrellevant:
#!/usr/bin/perl -w
# First, get the CGI variables into a list of strings
%cgivars= &getcgivars ;
print "Content-type: text/html\n\n" ;
open(MYFILE,"$cgivars{filename}") || die ("cannot open file!");
print MYFILE "$cgivars{output}" ;
close(MYFILE);
print "$cgivars{output}" ;
exit ; It's like that last print command just isn't working. The page just keeps displaying the applet instead of displaying what's supposed to be printed.
What I would really like to do is send the browser to the page that is created on the server. Unfortunately, I don't know how to do this with CGI. I do know how to do this with Javascript, but I don't want to add Javascript to this mess unless I have to - there's already too much room for bugs to crop up as it is.
There is another issue that doesn't matter unless it is somehow causing this problem. Here is my post-to-CGI Java code:
URL url = new URL(getCodeBase() + cgiFilename);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintStream out = new PrintStream(connection.getOutputStream());
out.println("filename=>" + URLEncoder.encode(directoryName + filename) + "&" +
"output=" + URLEncoder.encode(htmlText));
out.close();
DataInputStream in = new DataInputStream(connection.getInputStream());
in.close();Notice that I open an InputStream at the end and never use it for anything. This is because the file doesn't get written to the server unless I open an InputStream to the CGI file. I do not know why this is. It doesn't matter though unless this is somehow related to the print command not working.
Steven Fletcher