Member Avatar

I decided to develop a java applet to transfer files to a ftp server. I have no java experience but using stuff from the web and using NetBeans IDE for development, I came resonably close. Here is the code I used.

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

package chalaka;
import java.applet.Applet;

//public class NewApplet extends java.applet.Applet
public class FileUploadDemo extends Applet {

//public static void main(String[] args) {
public void init(){
    FTPClient client = new FTPClient();
    FileInputStream fis = null;
    try {
    client.login("cataloguserftp", "NuranMehara01");
    // Create an InputStream of the file to be uploaded

    String filename = "Touch.dat";
    fis = new FileInputStream(filename);
    // Store file to server
    client.storeFile(filename, fis);
    } catch (IOException e) {
    } finally {
    try {
    if (fis != null) {
    } catch (IOException e) {

This runs fine well run within the IDE but when I put this in a HTML, it gives following errors:

Java Plug-in 1.6.0_16
Using JRE version 1.6.0_16-b01 Java HotSpot(TM) Client VM
User home directory = C:\Users\chalaka

c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>

Exception in thread "thread applet-chalaka/FileUploadDemo.class-1" java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient
    at chalaka.FileUploadDemo.init(
    at sun.plugin2.applet.Plugin2Manager$ Source)
    at Source)
Caused by: java.lang.ClassNotFoundException:
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 3 more
Caused by: C:\Users\chalaka\Documents\NetBeansProjects\JavaApplication11\build\classes\org\apache\commons\net\ftp\FTPClient.class (The system cannot find the path specified)
    at Method)
    at<init>(Unknown Source)
    at<init>(Unknown Source)
    at[url]www.protocol.file.FileURLConnection.connect(Unknown[/url] Source)
    at[url]www.protocol.file.FileURLConnection.getInputStream(Unknown[/url] Source)
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$ Source)
    at Method)
    ... 7 more

Please help, thank you. see the HTML below:

   <TITLE>Applet HTML Page</TITLE>

*** GENERATED applet HTML launcher - DO NOT EDIT IN 'BUILD' FOLDER ***

If you need to modify this HTML launcher file (e.g., to add applet parameters), 
copy it to where your applet class is found in the SRC folder. If you do this, 
the IDE will use it when you run or debug the applet.

Tip: To exclude an HTML launcher from the JAR file, use exclusion filters in 
the Packaging page in the Project Properties dialog.

For more information see the online help.

<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>

<APPLET codebase="classes" code="chalaka/FileUploadDemo.class" width=350 height=200></APPLET>

<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.