简体   繁体   English

在JSP中嵌入Applet

[英]Embedding Applet in JSP

So I'm learning how to embed an applet into a jsp page. 所以我正在学习如何将applet嵌入到jsp页面中。 But the thing is, when I run the index.jsp, there's always an error. 但问题是,当我运行index.jsp时,总会出现错误。 The error says that the class for the applet is missing, and I don't know how to fix that. 错误说applet的类丢失了,我不知道如何解决这个问题。 I put the full class name of the applet in the index.jsp, and the jar file for the applet was made. 我将applet的完整类名放在index.jsp中,并创建了applet的jar文件。 Here is the code for the applet and jsp. 这是applet和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 ? 代码归属于.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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM