Getting Form Data to Web Server

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?

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

PhilippeConnect With a Mentor Commented:

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:


try {
String line;
String query_string =
    "name="+name+"&age="+age+"&balance="+balance ;
URL u = new URL(""+

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

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

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,


bbernatAuthor Commented:
I was impressed that Philippe actually included complete samples including a sample CGI script.
All Courses

From novice to tech pro — start learning today.