Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run applet in web application

Tags:

java

applet

I want to run simple applet in my web application using html applet tag but it gives error like

java.lang.ClassNotFoundException: MyApplet

please, give me sample application if possible .....

like image 254
chetan Avatar asked Nov 23 '10 07:11

chetan


People also ask

Can a Java applet be executed from a web browser?

A Java applet can be executed from a Web browser. The class name must be the same as the file name that contains the class. A file may contain several classes. Each class in the file is compiled into a separate bytecode file.

How an applet can be executed?

There are two standard ways in which you can run an applet : Executing the applet within a Java-compatible web browser. Using an applet viewer, such as the standard tool, applet-viewer. An applet viewer executes your applet in a window.

How do I associate an applet to an HTML file?

To run an applet in a browser or in the JDK Applet Viewer, the applet needs to be added to an HTML page, using the <APPLET> tag. You then specify the URL of the HTML page to your browser or the Applet Viewer. Note: Some browsers don't support easy, guaranteed reloading of applets.


1 Answers

the problem is that the applet engine can't find your MyApplet class at the codebase you have defined.

This can be caused because you have you class at your /WEB-INF/classes directory. This directory is protected by the servlet engine, for it not to be accesed from external resources (as can be an applet tag at a JSP/HTML page.

There are a few ways to solve this. The easiest one is to pack your MyApplet class un a jar file (let's call it myapplet.jar), and save it at an accesible directory (i.e. the jsp folder of your web application). As an example, supose you have the following folders for the web application:

/MyWebApp/jsp
/MyWebApp/applet
/MyWebApp/WEB-INF

The client browsers can access the content of jsp and applet folders.

Then, save your myapplet.jar at the applet folder, and set your applet tag configuration like this (suposing that you web context is MyWebApp):

<applet codebase="/MyWebApp/applet" archive="myapplet.jar" 
        code="MyApplet.class" width="600" height="500">
</applet>

Here you can find more info about the applet tag: http://docs.oracle.com/javase/tutorial/deployment/applet/index.html

like image 166
Tomas Narros Avatar answered Oct 21 '22 03:10

Tomas Narros