aspose file tools*
The moose likes Applets and the fly likes Applet Not Working on Web Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet Not Working on Web Server" Watch "Applet Not Working on Web Server" New topic
Author

Applet Not Working on Web Server

Mike Cutter
Ranch Hand

Joined: Jun 09, 2002
Posts: 49
I created an applet that utilizes the UNIX df command. I have a Choice where each UNIX hostname is listed. I have a Button that when clicked goes out an retrieves the output of the df command and puts into a TextArea.

With appletviewer, the applet works fine after I put the ".java.policy" file with "java.security.AllPermission" in the home directory. On Windows XP with Netscape and Internet Explorer, the applet works fine when I load the applet HTML file into the browser. Also on my IBM AIX system with Mozilla, the applet works fine when I load the applet HTML file into the browser.

On my IBM AIX system, I am using IBM HTTP Server which is using an Apache web server. From the URL of the web server, the applet is loaded, but nothing appears in the TextArea after clicking the Button. I have tried on Windows XP, AIX, Netscape, Internet Explorer, and Mozilla. The browser just has the message at the bottom "Applet DF started".

Can anyone give any ideas why the applet puts the df command in the TextArea as a local file, but not through the web server?

Thanks,

Mike Cutter
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42591
    
  65
Are you sure that the df command is the problem? Are there any exceptions in the Java console?


Ping & DNS - my free Android networking tools app
Mike Cutter
Ranch Hand

Joined: Jun 09, 2002
Posts: 49
This is what is the Exception in the Java Console.

Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: ch/ethz/ssh2/Connection
at DF.actionPerformed(DF.java:115)
at java.awt.Button.processActionEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

In order to connect to each UNIX client to run the "df" command, I use Secure Shell with the ganymed-ssh2-build208.jar which is where the Connection class is being referenced from.

I used this command and the applet worked:
appletviewer -J-Djava.security.policy=java.policy DF.html

This is the .java.policy file:
grant {
permission java.security.AllPermission;
};

This is the HTML file:
<applet CODE="DF.class" ARCHIVE="DF.jar,ganymed-ssh2-build208.jar" WIDTH=600 HEIGHT=750></applet>

In the Mozilla web browser with this URL accessing the local file, the applet worked:
file:///DFapp/DF.html

mcdunix is my web server's hostname. The applet is not working here.
http://mcdunix/DFapp/DF.html
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42591
    
  65
Is the jar file containing ch/ethz/ssh2/Connection where it is supposed to be? is it readable (meaning, can you download it manually)? Is it not corrupted?
Mike Cutter
Ranch Hand

Joined: Jun 09, 2002
Posts: 49
I am using a 3rd party ganymed-ssh2-build208.jar Secure Shell library file to obtain the df output from UNIX systems.

I extracted all the classes from the ganymed-ssh-build208.jar file. I then created a new jar file which contains the class files from my source code and the Secure Shell class files. Now this is a huge jar file. This resolved the Secure Shell references not being found.

If I properly put the .java.policy file in the home directory of each user on each system accessing using a web browser, the applet loads just fine. If there is no .java.policy file, I get AccessControlException errors. This will become problem because there is no possible way I am going to be able to copy the .java.policy in each and every home directory.

Is there a way to package the .java.policy security file into the jar file, so anybody can access the applet? Is there an alternative method that can circumvent the security issues with an applet other than the .java.policy file?

Mike
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42591
    
  65
Yes, there is another way: you can digitally sign the applet. There is more information linked in the Applet FAQ.

[ changed to include the link to the relevant FAQ page ]
[ January 06, 2006: Message edited by: Ulf Dittmer ]
 
 
subject: Applet Not Working on Web Server