質問

So I'm learning how to embed an applet into a jsp page. But the thing is, when I run the index.jsp, there's always an error. The error says that the class for the applet is missing, and I don't know how to fix that. I put the full class name of the applet in the index.jsp, and the jar file for the applet was made. Here is the code for the applet and jsp.

    package HelloApplet;

    import java.applet.Applet;
    import java.awt.Graphics;

    public class HelloApplet extends Applet {

        @Override
        public void paint(Graphics g) {
             g.drawString("Hello applet!", 50, 25);
        }//end paint

    }//end class

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <h1>Hello World!</h1>
            <br>
            <applet code="HelloApplet.HelloApplet" archive="HelloApplet.jar" width="600" height="480"/>
        </body>
    </html>
役に立ちましたか?

解決

Can the code attributte be a .jar ? Everything in the right directory?

Try something like this:

<applet code="HelloApplet.class" name="HelloApplet" archive="HelloApplet.jar"
    width=300 height=300>
    <param name="bgcolor" value="ffffff">
    <param name="fontcolor" value="000000">
    Your browser is not Java enabled.
</applet>

For more help, use this link

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top