How to put applet on another site

I have 2 Java applets (games <g>) I have developed.

The applet has several class files, and loads images and sounds

Sound code looks like this :

// many times, different variations
      excellentSound = getAudioClip( getDocumentBase(),
"sounds/" ) ;

// image code, different variations
      xhairImage = getImage(getDocumentBase (), "images/xhair.gif") ;

Now I wanna put the applet, images and support files on 1 web server (domain) and the HTML containing it on another (domain).

I tried putting CODEBASE= in the HTML.  This causes the applet to load from the new place, but as soon as it runs, I get a security exception in both IE and NS

1. What should I put in the HTML file
2. What code changes do I need to make in the applet
Who is Participating?

Improve company productivity with a Business Account.Sign Up

heyhey_Connect With a Mentor Commented:
>> Now I wanna put the applet, images and support files on 1 web server
>> (domain) and the HTML containing it on another (domain).

the you'll have to
1. replace (in the java code) all getDocumentBase() with getCodeBase().

2. use this applet directory structure -> applet classes (including main class) -> all sounds (including -> all images (including xhair.gif)

3. use this HTML code (html file is on another server
<applet codebase="" code=Animator.class width=460 height=160>

if this does not work, please post the whole security exception stacktrace.
Hi Answers2000,

This security problem is called Sandbox security problem in Applet running from browser.
Browser always sends request to same place from where HTML pages are loaded , so in CODEBASE , you can't give other domain name. For that  you have to configure web server to support this or you have to write proxy server so that browser only know that the applet is loading from same place from where html pages are loaded.

Try to read web server document for supporting CODEBASE ie in-built proxy server.

sandbox model means that applet is not allowed to connect with computer that differs from its originator.

xhairImage = getImage(getDocumentBase (), "images/xhair.gif") ; will give Security exception
xhairImage = getImage(getCodeBase (), "images/xhair.gif") ; won't give Security exception

HTML code is downloaded from the getDocumentBase() server
applet classes are downloaded from the getCodeBase() server.
applet is allowed to connect only with the second server (if they are different)

for a related question.
Answers2000Author Commented:
heyhey I think it's right, but it came too late for now...maybe I'll use it later

Take the points

heyhey - Please go to lounge and lock the Free Home Page question too - I was going to delete that one and give you extra the pts in the Java area, but Otta's scotched that idea now.

Atleast he gave the URL...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.