Lion
Lion

Reputation: 19037

How to embed an Applet into a JSP page?

I'm trying the following code in JSP to embed an Applet into a JSP page but it can't display it. The JSP code snippet goes below.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Analog Clock</title>
    </head>
    <body>

        <jsp:plugin align="middle" height="500" width="500" type="applet" 

        code="AnalogClock.class"  name="clock" 

         codebase="E:\JavaProNetBeens\JSPProject\web"/>

    </body>
</html>

Where AnalogClock.class is a class file already complied successfully and placed in the relevant JSP project itself that displays an analog clock. The relevant snap shot is as follows.


Applet doesn't display.


The browser tells that it requires some additional plugins. Which plugins are needed to display an Applet on the browser or something else is wrong in the above code snippet itself?


EDIT: Generated HTML source code is as under.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Analog Clock</title>
    </head>

   <body>

        <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" name="clock" 

        width="500" height="500" align="middle" codebase="http://java.sun.com/products

        /plugin/1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0">

        <PARAM name="java_code" value="AnalogClock.class">
        <PARAM name="java_codebase" value="E:\JavaProNetBeens\JSPProject\web">
        <PARAM name="type" value="application/x-java-applet;">
        <COMMENT>

        <EMBED type="application/x-java-applet;" name="clock" width="500" height="500" 

        align="middle" pluginspage="http://java.sun.com/products/plugin/"   

        java_code="AnalogClock.class" java_codebase="E:\JavaProNetBeens\JSPProject\web"/>

        <NOEMBED>
        </NOEMBED>
        </COMMENT>

        </OBJECT>

</body>


EDIT: The applet displayed using the <APPLET></APPLET> tag but still not displayed using <jsp:plugin/>. The changes I have made can be visible from the following tags.

<jsp:plugin align="middle" height="500" width="500" type="applet" 

code="AnalogClock.class"  name="clock" codebase="http://localhost:8080/JSPProject"/>

<APPLET code="AnalogClock.class" codebase="http://localhost:8080/JSPProject" 
align="baseline" width="200" height="200">

<PARAM name="model" value="AnalogClock.class">

      No Java 2 SDK, Standard Edition v 1.4.2 support for APPLET!!
</APPLET>

<jsp:plugin/> demands some additional plugins. Which plugins are required? or may it not run for some other reasons, please?

Upvotes: 0

Views: 7884

Answers (2)

JB Nizet
JB Nizet

Reputation: 692151

You need the Java plugin installed in the browser to run Java applets. Also, if you tell the browser that the codebase is E:\JavaProNetBeens\JSPProject\web, it will try to load it, on the client machine, in E:\JavaProNetBeens\JSPProject\web. And it will of course not find it.

The HTML page must load the applet using HTTP. And you must thus give an absolute HTTP URL, or a relative one from the path used to display the JSP.

Upvotes: 1

vbence
vbence

Reputation: 20343

It would be intresting to see the generated source code.

But how about instead of using macrros you create your object tag yourself like described here: Using OBJECT, EMBED and APPLET Tags in Java Plug-in

Upvotes: 3

Related Questions