applet in jsp from servlet, but error: ClassNotFoundExcep

The problem that I'm having is already mentioned a couple of times in this forum, but unfortunately I haven't found a solution, in thread http://forum.java.sun.com/thread.jspa?forumID=33&threadID=239405 is proposed solution but it's not working for me.

I'm developing a project in IBM's Websphere Developer Studio 5.1.1. and JRE that I'm using for this project is 1.4.2. I have created servlet "CompanyDocument.java" and applet "SimpleApplet.java". Applet was created as single project and then imported into this one, that means that it's contained in current project as "SimpleAppletPackage.jar". I have placed jar in folder "Applets", Websphere automatically creates folder "simpleAppletPackage" and in it's root complied "SimpleApplet.class".

When I put following code in the jsp page applet works correctly when application is runed.

<APPLET code="simpleAppletPackage/SimpleApplet.class" codebase="Applets" archive="SimpleAppletPackage.jar" width="250" height="250"></APPLET>

But I wanted to create jsp from servlet. So I used this code within servlet:

out.print("<APPLET code=\"simpleAppletPackage/SimpleApplet.class\" codebase=\"Applets\"");

out.print("archive=\"SimpleAppletPackage.jar\" width=\"250\" height=\"250\"></APPLET>");

But I get an error (when running, no error when compiling). The error is copied from Java console:

load: class simpleAppletPackage/SimpleApplet.class not found.

java.lang.ClassNotFoundException: simpleAppletPackage.SimpleApplet.class

at sun.applet.AppletClassLoader.findClass AppletClassLoader.java:162)

at java.lang.ClassLoader.loadClass(ClassLoader.java:289)

at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:123)

at java.lang.ClassLoader.loadClass(ClassLoader.java:235)

at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:566)

at sun.applet.AppletPanel.createApplet(AppletPanel.java:619)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(AppletPanel.java:548)

at sun.applet.AppletPanel.run(AppletPanel.java:299)

at java.lang.Thread.run(Thread.java:534)

Caused by: java.io.IOException: open HTTP connection failed.

at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:265)

at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:43)

at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:152)

at java.security.AccessController.doPrivileged(Native Method)

at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:149)

... 9 more

In the same time I'm creating some more code from servlet and it works with no errors and is shown in browser properly (it consists of connection to Oracle, formatting table, and presenting data within that table).

Any idea? I'm totally stuck.

[2954 byte] By [DeYoa] at [2007-10-2 10:41:03]
# 1

In your browser, look at the HTML code that gets sent to the browser and see if there is something wrong with it.

Specifically, I would look at the code near the <APPLET ..></APPLET> tags, both before and after and look for stray quotes, brackets, or what not.

Finally, I would look inside the <APPLET ...> tag. It appears to me that the output will probably be:

<APPLET code="simpleAppletPackage/SimpleApplet.class" codebase="Applets"archive="SimpleAppletPackage.jar" width="250" height="250"></APPLET>

See, you may be missing a space between the "Applets" and the archive=. Try making the second out.print look like this:

out.print(" archive=\"SimpleAppletPackage.jar\" width=\"250\" height=\"250\"></APPLET>");

See the extra space at the start of the output?

stevejlukea at 2007-7-13 2:48:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

try adding a space to the end of your first out.print statement.

out.print("<APPLET code=\"simpleAppletPackage/SimpleApplet.class\" codebase=\"Applets\""); ><- add space here

out.print("archive=\"SimpleAppletPackage.jar\" width=\"250\" height=\"250\"></APPLET>");

slenzia at 2007-7-13 2:48:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Oops, I see that the other poster already found the bug... oh well.-S
slenzia at 2007-7-13 2:48:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
No, this is not working.Here is the output of the html:<P><APPLET codeBase=Applets height=250 archive=SimpleAppletPackage.jar width=250 code=simpleAppletPackage/SimpleApplet.class></APPLET>
DeYoa at 2007-7-13 2:48:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

I have found the solution.

The first line passed from servlet needs to be:

out.print("<P><APPLET code=\"organigramPackage/JungSimple.class\" codebase=\"../MyApplets/\" ");

For some reason, the relative path of codebase needs to point "one foder up".>

DeYoa at 2007-7-13 2:48:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Should we try something likeout.println("<applet code=appletname" + "codebase='/'>" + "</applet>")I mean breaking up the strings and concatenating them with the '+' operator
dumb_javaa at 2007-7-13 2:48:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...