How to make an applet save some data in a txt file at the ftp/server?

EDIT : Look at my last post to see , I changed my mind and hence changed the problem.Did not wanna start a new topic.

make the action of the submit

mailto:whoever@whereever.com

I meant … hm … mailto , whose method is it?Or u mean html ?

It’s an html thing

<a href="mailto:whoever@whereever.com">Email Link</a>

EDITED :

Basically I changed my mind.As I described this is an applet.It shows 3 JTextFields and a JButton.I have this applet uploaded in my ftp and I run it from an index.html . I want to take what is contained inside the JTextFields and write it inside a .txt file which is in my ftp called form.txt . Here is the whole code of the applet.It does not work.It loads the applet with its fields and the submit button but it does not write anything in the .txt file.

It is my first ever attempt at an applet so please excuse my inexperience.I tried many stuff … been googling and checking tutorials and Streams … and tried to wrap all streams I could find but still I could not do it :confused: .Plz help me understand it because I really am at a loss as to how I should do it.So … here is the code :

(note it was supposed to be somethign nice I wanted to make for my guild @ World Of Warcraft … but damn me , it always is so easy in theory , but never in practise :confused: )




import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.URL;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;


public class DLFormApplet extends JApplet
{
    
    public void init()
    {
        DLForm form = new DLForm();
        add(form);
        
    }
}

class DLForm extends JPanel
{
    JPanel buttonPanel , mainPanel;
    JButton submitButton;
    JTextField contractorsName , targetsName , emailField;
    String form;
    FileOutputStream out;
    PrintStream p ;
    URL url;
   
       
    public DLForm()
    {
        SubmitListener l = new SubmitListener();
        buttonPanel = new JPanel();
        submitButton = new JButton("Submit");
        buttonPanel.add(submitButton);
        add(buttonPanel , BorderLayout.SOUTH);
        
        mainPanel = new JPanel();
        mainPanel.setLayout(new GridLayout(0,2));
        add(mainPanel , BorderLayout.CENTER);
        
        url = this.getClass().getClassLoader().getResource("form.txt");
        
         try
        {
            out = new FileOutputStream(url.getFile());
        }
        catch(Exception e)
        {
            e.getStackTrace();
        }
       
        
        contractorsName = new JTextField();
        addRow("Enter your character's name here:" , contractorsName);
        contractorsName.getDocument().addDocumentListener(l);
        
        targetsName = new JTextField();
        addRow("Enter target's name here:" , targetsName);
        targetsName.getDocument().addDocumentListener(l);
        
        emailField = new JTextField();
        addRow("Enter your email here:" , emailField);
        emailField.getDocument().addDocumentListener(l);
    
        submitButton.addActionListener(l);
        
     
    }

    public void addRow(String label, JTextField textField)
    {
        mainPanel.add(new JLabel(label));
        mainPanel.add(textField);
        
    }
    
    public String submit()
    {
        String s;
        s = "Contractor's name : "+contractorsName.getText()+"\n"+
                "Target's name : "+targetsName.getText()+"\n"+
                "Contractor's email : "+emailField.getText();
        return s;
    }
    
    private class SubmitListener implements ActionListener , DocumentListener
       {
           public void actionPerformed(ActionEvent event)
                    {
                        form = submit();
                        try
                        {
                        p = new PrintStream(out);
                        p.println(form+"\n");
                        p.println("ELEOS !!!! ELEOS !!!");
                        p.close();
                        }
                        catch(Exception e)
                        {
                            e.printStackTrace();
                        }
                    }

        public void insertUpdate(DocumentEvent e) 
        {
        }

        public void removeUpdate(DocumentEvent e) 
        {
        }

        public void changedUpdate(DocumentEvent e)
        {
        }
       }
    
}

One way or another you are going to have to transfer uisng the FTP server which means FTP protocol.

You might want to start here:
http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp.html

Hey Jeff thanks a lot ! I read the whole article and decided that I would use Jakarta Commons/Net library.But you see I have never used another library before other than the standard code which comes with jdk.So I am not sure as to how I can import it in my code.

I did as some tutorials suggested , adding the commons-net-1.4.1-src.zip in the classpath but I can not import from it.I tried playing around with its position but nothing worked so far.How do you use a library you jave just downloaded in your code?I have never done that before ???

Also later … when I will want whoever acceses the ftp server to be able to do that thing I want , where in the ftp should I put the library ? I am confused as to how this whole thing works

[quote=“Avenger,post:7,topic:27024”]
That zip is the source code (thus the “-src”). You want to get a jar of the compiled commons-net classes and add that to your classpath.
You could also unzip the file you have and build the jar from the source.

hmmm and how do I build a jar file?I mean … I should take the src/java/org/ .java files from in there and how do I make them all in a jar fie?

You would follow the instructions for building it that you find on the Jakarta Commons web page…

http://jakarta.apache.org/commons/building.html

… they seem unnecessarily complicated… “maven” is a bit harder to use than “ant”… so…

Just go here http://jakarta.apache.org/site/downloads/downloads_commons-net.cgi
and download the binary distribution instead of the source.

To add a Jar:

If you are in an IDE you generally set it in projedct properties.

If you are on the command line you put a reference in your classpath:
eg java --classpath .;foo.jar

However it looks like you downloaded source not the jar This means you are either going to have to put it in with ther est of your source code to compile as aprt of your own source base OR compiel it yourself seperately into a JAR

or go find one thats already compield into a JAR for you.

See above. If the JAR also has a native portion with it (ftp shouldnt) then you also need to make that dll/so/whatever your local natvie format dynamic load library is available on your library load path.

Thanks to both of you.I did a quick scan of what you said and I think I understood it , but I will have to test it more thoroughly later though.I will be at my parents house for the next 4 days without a computer , so I will check it when I come back and tell you if it worked.Thanks again :slight_smile: