tags:

views:

39

answers:

3

I have developed a JSP webapplication with an Applet. I am not able to display the applet from my JSP page.

Below is the code:

<applet codebase="http://localhost:8080/av_applet_jsp/applets" code="av_app.class" WIDTH="200" HEIGHT="100">

av_app.class is located inside Webcontent/applets/

Where I am going wrong?

Here is my applet class:

public class av_app extends Applet {

    @Override
    public void paint(Graphics g) {
        int inset;
        int rectWidth, rectHeight;
        g.setColor(Color.pink);
        g.fillRect(0,0,300,160);
        g.setColor(Color.green);
        inset = 0;
        rectWidth = 299;
        rectHeight = 159;
        while (rectWidth >= 0 && rectHeight >= 0) {
            g.drawRect(inset, inset, rectWidth, rectHeight);
            inset += 15;
            rectWidth -= 30;
            rectHeight -= 30;
        }
    }
} 

I am able to see applet using applet viewer. What I am doing wrong in my JSP page?

When I tried an example code it's working:

<applet codebase="http://java.sun.com/applets/NervousText/1.1"
    code="NervousText.class" width=400 height=75>
  <param name="text" value="Welcome to HotJava!">
</applet>
A: 

What happens when you browse to http://localhost:8080/av_applet_jsp/applets? Is your class file there?

On another note, it appears that you did not package your applet as a JAR. Why not?

justkt
Packaging is not necessary for an applet to function. It's however indeed the recommend way to distribute it whenever you've more than one class.
BalusC
@BalusC - I do realize that (dug through and checked), but was curious since it seems to be a standard.
justkt
It was just to avoid OP getting more confused :) Packaging is not necessarily the root cause of his problem.
BalusC
yeah class file is present in the location " http://localhost:8080/av_applet_jsp/applets "
evan
A: 

With a codebase of..

http://localhost:8080/av_applet_jsp/applets

..and code attribute of..

av_app.class

..the JVM will be looking for the class in..

http://localhost:8080/av_applet_jsp/applets/av_app.class

OTOH you state the applet is actually located at..

http://localhost:8080/Webcontent/applets//av_app.class

Either move the class to where the applet is expecting to find it, or change the HTML to look where it is located.

Andrew Thompson
my class is located at " http://localhost:8080/av_applet_jsp/applets/av_app.class "
evan
A: 

problem was i also mentioned package name in the class ,after removing its working fine ,thnkx for the answers guys

common help

"http://download.oracle.com/javase/tutorial/deployment/applet/problemsindex.html"

evan