DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    1

    Angry Applet...can't write to file on server

    Hi y'all...

    I'm really in need of someone who knows Java applets and CGI-scripting. I am trying to use my Java applet (game) to read/write from/to my webserver. I've managed to accomplish the read-part...Now the writing is a lot more difficult. I know about the security issues and all. My applet is communicating with a CGI-script on my webserver...Now; the code and all looks fine (to me), but it just will not work:

    The part of my Java code that handles the writing-procedure is the following:


    public void SendData(String data) throws Exception {
    try{
    URL fileUrl = new URL("http://ftp.domain.nl/~user.domain.nl/public_html/Game/wdwrite.cgi");
    URLConnection url = fileUrl.openConnection();

    url.setUseCaches(false);
    url.setRequestProperty("Content-Type", "text/plain");
    url.setDoInput(false);
    url.setDoOutput(true);

    PrintStream outStream = new PrintStream(url.getOutputStream());
    outStream.print(data);
    outStream.flush();
    outStream.close();

    url.setDoInput(true);
    url.setDoOutput(false);
    BufferedReader inFile = new BufferedReader(
    new InputStreamReader(
    url.getInputStream()));

    String inStr = new String();
    while ((inStr = inFile.readLine()) != null){
    System.out.println(inStr+"\n");
    }

    inFile.close();

    }
    catch(MalformedURLException ex1)
    {
    System.out.println("URL not found...");
    }
    catch(IOException ix1)
    {
    System.out.println("File not found...");
    ix1.printStackTrace();
    }


    }


    This should do the trick, some experts say on the Internet...Now, my CGI-script looks like this:


    #!/usr/bin/perl
    # wdwrite
    # this is the CGI that will take the # applet info and write it to a file

    print "Content-type: text/plain\n\n";
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # the amount of data coming in.

    open(OUTF, ">>scorelist.txt");
    print OUTF $buffer;

    close (OUTF);
    exit 0;


    That's all...looks great...but does not work :'(
    What is the problem? Btw: all the files are in the same directory, namely: http://ftp.domain.nl/~user.domain.nl/public_html/Game/

    and of course domain stands for something else....Hope one of you can figure it out...I can not...

    Thanx already!

  2. #2
    Join Date
    Feb 2004
    Posts
    808
    something like this may be of use to you:

    http://www.j-nine.com/pubs/applet2servlet/index.htm

    its geared towards a servlet to receive the data, but im sure your familiarity with cgi will allow you to read the post data..
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links