Calling Applet to server. Somebody help me please! I'm a student and I know that Applets aren't really meant to behave this way - and even if they do, they may not be allowed to due to local Firewall restrictions. So, my appeal for help is as much academic as it is practical. So, please don't tell me about servlets or the magic of JSP. I want my Applet to talk! The Applet program is listed here (below) and this accesses a Perl cgi-bin script on my localhost (127.0.0.1) Apache server;-
while (<>) { print OUT $_; print $_; } close (OUT); exit 0; # end of script
I'm a total beginner with Perl, so I don't have the first clue how to correct the Perl Script, if it is wrong. When I check the server log, it says it has accessed the script with the following message;-
"POST /cgi-bin/wdwrite.pl HTTP/1.1" 200 64
Here, also is the Applet. It's quite a simple progam;-
/** postMethod.java - see also wdwrite.pl * Textfied and button. The button calls to a function writePage() * this then gets the host() and opens a URL connection to send the * data out, back to the place the Applet came with a dataOutputStream * object and writeBytes() and linked back to a Perl cgi-bin program. */
import java.applet.Applet; import java.net.*; import java.io.*; import java.awt.*; import java.awt.event.*; //Tidy these up later with .ActionEvent etc;
public class postMethod extends Applet implements ActionListener { TextArea info; Button Bsend; String str; String host, conext, exc1, exc2;
//*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X // init the textfield and button. Only the button needs ActionListener
public void init() { info = new TextArea(5,68); add(info); Bsend = new Button("SEND"); Bsend.addActionListener(this); add(Bsend); }
//*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X / / show the results or exceptions in a series of strings
public void paint (Graphics g) { g.drawString("Got this: "+str, 30, 150); // message 2B sent g.drawString(host, 30, 170); // getHost().getCodeBase() g.drawString(conext, 30, 190); // getConnection.toSting() g.drawString(exc1, 30, 210); // didn't like the call to host g.drawString(exc2, 30, 230); // didn't like the writeBytes() }
//*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X* // button links to the Post Method and calls the function writePage()
public void actionPerformed(ActionEvent e) { if (e.getSource() == Bsend) { str = info.getText(); try { writePage(); // Has to be caught } catch (Exception e1) { exc1 = "writePage: " + e1.toString(); } } repaint(); // exceptions /results etc }
//*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X* // writePage function returns to repaint. Links the page back to // whence it came and directs it to the Perl script in cgi-bin // Note: try-catch are not necessary here. ie: it should still work // without this. The purpose is to catch an error message should // an error occur. Sent as a String in repaint() g.drawString