Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting Form Data to Web Server

Posted on 1997-04-30
2
Medium Priority
?
173 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 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

721 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