Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Joe Ess
  • salvin francis
  • fred rosenberger

java Applet using cgi-bin - help a young lady in distress

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling Applet to server. Make my Applet work.
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 ( Apache server. I am using Windows (98 se) and
have created a public_html folder and even tried with a opinion.txt file;-
#! C:\perl\bin\perl.exe
open(OUT, "> /public_html/opinion.txt");
print "content-type: text/plain\n\n";

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/ HTTP/1.1" 200 64
Here, also is the Applet. It's quite a simple progam;-
/** - see also
* 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.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;
// init the textfield and button. Only the button needs ActionListener
public void init() {
info = new TextArea(5,68);
Bsend = new Button("SEND");
// 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()
// 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
// 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
public void writePage() throws Exception {
host = getCodeBase().getHost();
try {
URL url = new URL("http://"+host+"/cgi-bin/");
URLConnection con = url.openConnection();
conext = "connect OK: " + con.toString();
con.setRequestProperty("Content-type", "text/plain");
con.setRequestProperty("Content-length", str.length()+" ");

DataOutputStream out = new DataOutputStream(con.getOutputStream());
String content = URLEncoder.encode(str);
exc2 = "Seems OK: reads to final line.";
catch (Exception e2){
exc2 = "dataOutputStream: " + e2.toString();
}// end try-catch
}// end writePage()
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Come off it Walter, you can't get help with this "young lady in distress stuff".
This tiny ad is suggesting that maybe she should go play in traffic.
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!