Solved

Getting Form Data to Web Server

Posted on 1997-04-30
2
167 Views
Last Modified: 2010-04-16
I have a form applet running and working the way I want.  Now comes
the next step, appending the data (just some tab-delimited field data in a
single line terminated by newline) to a file on my web server.  I haven't
found an easy way to do this, but I'm sure its just my ignorance.

My book shows me rather simply how to append to a file, but doesn't address
appending to a file on a web server.  Can anyone make a recommendation?

Thanks!,
0
Comment
Question by:bbernat
2 Comments
 
LVL 2

Accepted Solution

by:
Philippe earned 50 total points
ID: 1219995
bbernat,

This is simple. Just make a simple cgi on your server which will append the data it receives to a file. Then have your applet call that cgi with the data. Note that you better do the formating in the cgi rather than in the applet as your data will be translated into an URL)

Here is an example, three values are appended to a file:

applet:

try {
String line;
String query_string =
    "name="+name+"&age="+age+"&balance="+balance ;
URL u = new URL("http://myserver.com/cig-bin/myscript?"+
                query_string);

// call the script and get any answer
DataInputStream s = new DataInputStream(u.openStream());
while ((line = s.readLine()) != null)
 showStatus(line);
}
catch (Exception e) {
  System.err.println(e);
}

The cgi-script (in unix shell ) would look like this:

#!/bin/sh
echo "Content-type: text/ascii"
echo ""
 
#get the different variables out of the query_string
 
eval `echo $QUERY_STRING | sed -e 's/'"'"'/%27/g' | \
      awk 'BEGIN{RS="&";FS="="}
          $1~/^[a-zA-Z][a-zA-Z0-9_]*$/ {
          printf "QS_%s=%c%s%c\n",$1,39,$2,39}' `

#append to the file
echo $QS_name "   " $QS_age "   " $QS_balance >> myfile

echo "thanks for your data"


Hope this helps,

  Philippe

0
 

Author Comment

by:bbernat
ID: 1219996
I was impressed that Philippe actually included complete samples including a sample CGI script.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java DateChooser? 3 36
Java SE 8u111  Lot of stuff broke 11 69
configure dependency in POM for new database 3 25
Java Restore security prompts not working 10 12
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question