Solved

Getting Form Data to Web Server

Posted on 1997-04-30
2
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses

624 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