Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

HELP! Servlet calling Applet

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Servlet calling an applet, but I get a FileNotFoundException.
I call the applet like so -
m_pwOut.print("<APPLET CODE='DavesApplet.class' WIDTH=50 HEIGHT=50 CODEBASE='/applet'>");
The Dir structure in tomcat is like so -
myApp/web-inf/classes/com/davespackage/servlet.class
myApp/applet/DavesApplet.class
And this is the exception I get -
load: class DavesApplet.class not found.
java.lang.ClassNotFoundException: java.io.FileNotFoundException: File not found: http://localhost:8080/applet/DavesApplet/class.class
at sun.plugin.protocol.jdk12.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
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)
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at sun.plugin.security.PluginClassLoader.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)
Any Ideas???
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason is that the browser is looking for the applet class files in the wrong place. You need to either:
1. Give a complete URL for the CODE
2. Put a <BASE> tag in the head area of the html page that points to the location of the class files.
I prefer 2 because that also gives the browser where to look for graphics and other resources.
The syntax is:
<BASE HREF="someURL" >
 
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Semantically speaking, a servlet cannot "call" an applet. The best you can do is have a servlet respond to a request with HTML that causes (we hope!) the user's CLIENT (browser) to request the applet (assuming you're not running "new and improved" Internet Explorer which doesn't have support for that silly old useless Java :roll: (Bill Gate's opinion, not mine).
Files pulled by the browser are pulled in exactly the same way whether they're html, gif, OR jar or classfiles. In other words, the WEB-INF/classes classpath is meaningless to the client. Only the SERVER uses that path. The applet's classes aren't going to be executed on the server, just copied to the client so IT can execute them, so the place to put them is in a copyable directory.
From your sample, I think you got that straight. However, if that a verbatim error message, why is it looking for a class file named "class.class?" I'd check that applet tag again.
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u can also try using CODEBASE="/myApp/applet".
 
    Bookmark Topic Watch Topic
  • New Topic