This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Applets and the fly likes Argh....all I want to do is load this applet.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Argh....all I want to do is load this applet.." Watch "Argh....all I want to do is load this applet.." New topic
Author

Argh....all I want to do is load this applet..

Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
I'm trying to load an applet I wrote from a web page (JSP). It will load just fine when I do it locally inside an HTML page, but when I try accessing it from the web server it says that the applet cannot be found.

Here is what I have:




The page loads fine but the applet will not load because it cannot find the DisplayMonoApplet.class.

Here is the exact error:

load: class DisplayMonoApplet.class not found.
java.lang.ClassNotFoundException: DisplayMonoApplet.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Caused by: java.io.IOException: open HTTP connection failed.
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 10 more

My DisplayMonoApplet can be found in the WAR file in the following location:
WEB-INF\classes\myapp\DisplayMonoApplet.class

I have tried every configuration I can think of (myapp/DisplayMonoApplet, http://myserver:18080/myapp/.....etc.) but no luck.

I've tried using a CODEBASE too but still no luck.

Please help me find out what I'm doing wrong before I go insane!

THANKS!
[ May 06, 2005: Message edited by: Darrin Smith ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The applet class files are requested directly from the webserver by the browser. Therefore, they have to be in publically accessible web space. They cannot be anywhere inside of WEB-INF, because this directory is quite deliberately not served from.

Basically, the applet class files need to be at the top level of the web app, or in a jar file at some stated path below that top level -- but not in WEB-INF.


[Jess in Action][AskingGoodQuestions]
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
OK, so I need to move the applet outside of WEB-INF.

So for example, if I place it in my C:\web_app directory, then to get to it all I need to do is:

CODE = "DisplayMonoApplet.class"
CODEBASE = "http://myservermachine/"

It will still be in the WAR file, just not under the WEB-INF directory then.

Is this right?

THANKS!!!
[ May 07, 2005: Message edited by: Darrin Smith ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Yes, sounds good.
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
Well, being at home I couldn't try the actual case decribed above, but I worked up a quick test using the old Applet tag and not loading the plugin and did a quick HelloWorld style applet, and sure enough as you thought, it works when I put the applet at the top (not inside the web-inf)!

On Monday I'll convert what I have at work to the way you suggest and see if it still works with the extra plugin code and all.

I've never distributed an applet (servlets yes...plenty of those) through a web server before and didn't know it was restricted that way.

MANY THANKS!
Sudha Rams
Greenhorn

Joined: May 13, 2005
Posts: 12
Thanks. This works!!
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276


Am I doing anything wrong, or does it just hate me?


Note that the commented out plugin command was the way it looked (and worked) before I placed the applet and its supporting classes inside the jar file.

Thanks!
[ May 20, 2005: Message edited by: Darrin Smith ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

For jar files, you need to drop the "codebase" attribute and use "archive" instead. "Codebase" signifies a directory full of loose classes only.
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
Originally posted by Ernest Friedman-Hill:
For jar files, you need to drop the "codebase" attribute and use "archive" instead. "Codebase" signifies a directory full of loose classes only.


Doh!!

I guess that is why I couldn't find much when I serache for codebase being used with jar files in plugins.

I'll change codebase="http....." to archive="http:...." and give it a try.

Thanks!
Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
Yup, that did it!

I really appreciate it!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Argh....all I want to do is load this applet..
 
Similar Threads
Possible to pass a run time param?
Reg: Running Swing in Browser
Runtime parameter changes
3 problems with my applet...
Swing back to AWT