Solved

How to put applet on another site

Posted on 1999-01-27
5
216 Views
Last Modified: 2008-03-17
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/excellent.au" ) ;

// 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

So
1. What should I put in the HTML file
2. What code changes do I need to make in the applet
0
Comment
Question by:Answers2000
5 Comments
 
LVL 16

Accepted Solution

by:
heyhey_ earned 50 total points
ID: 1234810
>> 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
www.server.com/applet/ -> applet classes (including main class)
www.server.com/applet/sounds/ -> all sounds (including excellent.au)
www.server.com/applet/images/ -> all images (including xhair.gif)

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

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

Expert Comment

by:ssbera
ID: 1234811
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.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1234812
ssbera.

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

Thus
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)
0
 
LVL 12

Expert Comment

by:Otta
ID: 1234813
See: http://www.experts-exchange.com/Q.10121989

for a related question.
0
 
LVL 8

Author Comment

by:Answers2000
ID: 1234814
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...
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 53
Application launch issue with Apache Tomcat 5 45
advertisement module in core php 4 162
check java version using powershell 13 93
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question