• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to reference Applets in a Java Web Application

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic