Solved

Getting Form Data to Web Server

Posted on 1997-04-30
2
162 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now