JSP Applet Plugin

JSP Applet Plugin


Posted in : Java Posted on : May 2, 2012 at 6:34 PM Comments : [ 0 ]

In this tutorial you will learn about the plugin of applet in JSP.

JSP Applet Plugin

In this tutorial you will learn about the plugin of applet in JSP.

To plugin an Applet in a JSP page an action element jsp:plugin is used. Using this element a bean can also be included in a JSP page. This element generates the html to download the Java plug-in (in case of not installed) and executing an applet. An OBJECT element or the EMBED element are generated by this action for the IE (Internet Explorer) or the NN (Netscape Navigator) respectively. The jsp:plugin action element, when the JSP page is executed, is substituted with either the <OBJECT> or the <EMBED> html tag, based on the browser.

Attributes of jsp:plugin

  • type = "bean | applet" :- bean or applet object executed by the plugin.
  • code = "classFileName" :- A java class file which has to be executed by the plugin. Extension of this file name must be the .class.
  • codebase = "classFileDirectoryName" :- Directory name of the Java class file. i.e directory of code attribute classFileName.
  • align = Specifies the alignment.
  • archive = Specifies the list of archives.
  • height = Specifies the height.
  • hspace = Specifies the horizontal space.
  • jreversion = Specifies the version of jre.
  • name = Specifies the name of component.
  • vspace = Specifies the name of vertical space.
  • width = Specifies the width.
  • nspluginurl = overrides the default url where the plug in can be downloaded.
  • iepluginurl = overrides the default url where the plug in can be downloaded.
  • <jsp:params> = sub element of jsp:plugin that defines the parameters for the applet or JavaBeans component.
  • <jsp:param> = sub element of jsp:params that specifies the name and value of the parameter.
  • <jsp:fallback> = Acts when the plug-in can not be started and suggests the content to be used by the client browser.

Example :

Here a very simple example is being given which will demonstrate you about how to use the jsp:plugin action element for deploying applets with Java Plug-in. In this example I have created first an Applet then created a JSP page where I have used <jsp:plugin> action.

JspPluginApplet.java

import java.applet.*;
import java.awt.*;
import java.util.*;

public class JspPluginApplet extends Applet {
public void paint(Graphics g){
Calendar cal = new GregorianCalendar();
String hour = String.valueOf(cal.get(Calendar.HOUR));
String minute = String.valueOf(cal.get(Calendar.MINUTE));
String second = String.valueOf(cal.get(Calendar.SECOND));
g.drawString(hour + ":" + minute + ":" + second, 20, 30);
}
}

jspPluginApplet.jsp

<jsp:plugin type="applet" code="JspPluginApplet.class" codebase="test"
width = "200" height = "200">
<jsp:fallback>
<p>Unable to load applet</p>
</jsp:fallback>
</jsp:plugin>

How to run this example

To execute this example you will have first compiled the Applet and then put the class file in a folder (in my case "test1") into your web folder (in my case WebContent folder, because here, I am using the eclipse editor to run the program). Then execute the JSP page.

Exception may be thrown :

When you will execute the JSP page the jsp:plugin is started but the applet or JavaBeans component is not found a message (plug-in specific) will be displayed to the user, generally a pop-up window represents a ClassNotFoundException.

Output :

Directory Structure may be as follows :

When you will execute the above JSP page you will see the time is displaying in the web page.

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics