aspose file tools*
The moose likes Applets and the fly likes How to reference Applets in a Java Web Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "How to reference Applets in a Java Web Application" Watch "How to reference Applets in a Java Web Application" New topic
Author

How to reference Applets in a Java Web Application

Kerry Baer
Ranch Hand

Joined: Jun 23, 2010
Posts: 39
I am using Netbeans 7.0.1. I have a Java Web Application in which I want to execute an applet on one of my pages. The web application uses Hibernate and Spring frameworks.

I have created an applet using the AWT GUI Forms, AppletForm template. I placed this in a package call com.applet.

The page I am currently attempting to get the applet to run on is located at /WEB-INF/jsp/index.jsp. The URL for this when deployed locally is http://localhost:8080/myApp/index.htm.

I have tried several times using the <applet>, <object> and <embed> html tags to bring the applet into the page. Every time the Java Console reports a ClassNotFoundException.

Here is an example of the html I have tried to use to reference the applet...



I am not used to working with Applets, so any help with this is greatly appreciated.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

The WEB-INF folder and its subfolders in your web application are not accessible to the client. But the applet runs on the client, and loads its classes from there. So you'll have to change your codebase attribute so that it refers to a folder which IS accessible to the client.
Kerry Baer
Ranch Hand

Joined: Jun 23, 2010
Posts: 39
Paul Clapham wrote:The WEB-INF folder and its subfolders in your web application are not accessible to the client. But the applet runs on the client, and loads its classes from there. So you'll have to change your codebase attribute so that it refers to a folder which IS accessible to the client.


So, in other words... I need to compile my applet and put the compiled class code in a directory that can be see by the web-at-large?

Let's say that my css reference looks like this in the header =>


If my compiled applet is in directory called "applet" that is under the same folder as "css", then what would the codebase reference be? What would the "code" property be set to.

For example: if the applet was referenced the same way as a <link> for css, then the path would look like this:
Kerry Baer
Ranch Hand

Joined: Jun 23, 2010
Posts: 39
So far it looks like the best solution to this problem is explained in the following tutorial => Integrating an Applet in a Web Application

I would have liked to do this without having to create a separate project, but this solution seems to be the best option.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Kerry Bear wrote:So, in other words... I need to compile my applet and put the compiled class code in a directory that can be see by the web-at-large?


Yes, that's a one-sentence summary of exactly what you have to do.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

Kerry Bear wrote:I would have liked to do this without having to create a separate project, but this solution seems to be the best option.


Creating a separate project seems a bit extreme (although it could have its positive features in some cases). I'm using Eclipse and not Netbeans, but they are pretty simple. I just wrote a simple Ant task which takes the compiled applet classes and puts them into a jar under the equivalent of your "web" folder. You could do the same thing, couldn't you? Or just have Ant copy the class to somewhere under "web"?
Kerry Baer
Ranch Hand

Joined: Jun 23, 2010
Posts: 39
Paul Clapham wrote:
Creating a separate project seems a bit extreme (although it could have its positive features in some cases). I'm using Eclipse and not Netbeans, but they are pretty simple. I just wrote a simple Ant task which takes the compiled applet classes and puts them into a jar under the equivalent of your "web" folder. You could do the same thing, couldn't you? Or just have Ant copy the class to somewhere under "web"?


Yes. That's what the link I posted above instructs me to do. I just include the applet project in my Web application project. Then when I build the web application, Netbeans also compiles the applet project and places it's jar file in the Web directory making it available to my web pages. I've not got it running in this manner.

I appreciate your assistance with this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to reference Applets in a Java Web Application