Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applets loading local classes?

 
paul wheaton
Trailboss
Pie
Posts: 21880
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet that I'm trying to have get info from a servlet. This applet uses another class that accesses the servlet.
I load the applet and the class it uses on the web server. When I try to activate it, I get the following message: "netscape.security.AppletSecurityException: security.class from local disk trying to access url: http://myurl.com/servlet/DQServer"
My guess is that somehow netscape is loading the applet and using classes in my classpath rather than the ones on the server.
Any ideas how to fix this?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the obvious solution is to prune the classpath passed to the browser, so that the duplicated class is not found locally. If that's not feasible, you could try renaming or repackaging either the remote or local versions.
If the class you are trying to load has a different name and/or different package they shouldn't clash.
The key thing to remember is that in the vast majority of cases it's a good thing to be able to use local classes rather than having to download potentially hundreds of K of bytecode everytime you want to use an applet. That would get very irritating very fast.
 
paul wheaton
Trailboss
Pie
Posts: 21880
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that I'm making a class called HTTP that communicates with a servlet. It's in a com.company.common sort of directory. The com.company directory tree is copied to the directory that the applet is in.
Naturally, since this is my development computer, my CLASSPATH points to the com.company stuff. People accessing the applet outside of the company won't have this problem, but I do.
When I load the applet, it wants to use the HTTP class. Unfortunately, it pulls it off of my hard disk and the HTTP class tries to open a connection to a servlet on the server that the applet came from.
So, it seems there should be a way to tell the browser to stop looking at my local classpath and focus only on the applet directory.
Is there such a beast?

 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the exact solution depends on which browser(s) you are using and on which system. As far as I can tell, a browser usually gets its classpath from the enclosing environment, so if you were to put together a shell script or .bat file which sets CLASSPATH to whatever subset you prefer, and then runs the browser, you could use that to start the browser instead.
To ensure the browser gets everything from the remote system, you could probably get away with a completely empty CLASSPATH.
I have done this sort of thing successfully on a variety of systems with a variety of browsers in the past. If you're still having no luck, let me know a few more details (Browser + version, OS + version, shell or command interpreter if appropriate, JDK version etc.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic