Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training

Using Applet in JSP

Applet is java program that can be embedded into HTML pages. Java applets runs on the java enables web browsers such as mozila and internet explorer.


Using Applet in JSP


Example program which illustrates use of <jsp:plugin> tag to include Applet in JSP page

What is applet ?

Applet is java program that can be embedded into HTML pages. Java applets runs on the java enables web browsers such as mozila and internet explorer. Applet is designed to run remotely on the client browser, so there are some restrictions on it. Applet can't access system resources on the local computer. Applets are used to make the web site more dynamic and entertaining. For reading more detail on apple visit:


To use applet in JSP page we can use <jsp:plugin>. By the use of <jsp:plugin> you can include an applet and JavaBean in your JSP page. Syntax of <jsp:plugin> is :

   [ name="instancename" ]
   [ align="bottom|top|middle|left|right" ]
   [ height="displayPixels" ]
   [ width="displayPixels" ]
   [ jreversion="JREVersion" ]
  ................. >
   <jsp:param name="parametername" 
   value="parametervalue" />

   text message


  1. type: this is the type of object plugin will execute. You have to specify it either bean or applet since it has no default value.
  2. code: name of the java class file. You must have to write ".class" with class file name.
  3. codebase: absolute or relative path of directory where applet code file exists.
  4. name: name of bean or applet instance.
  5. align: position of applet or bean display on the browser.
  6. height: as its name signifies, height of applet or bean display
  7. width: as its name signifies, width of applet or bean display
  8. jreversion: version of Java Runtime environment 
  9. <jsp:params>: name and parameters value passed to applet or bean.
  10. <jsp:fallback>: a text message to be displayed if applet plugin cannot be started.

To plugin an applet in JSP page we require an applet. So we have made an applet "". Code for this applet file is given as below:

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

public class ButtonMoveApplet extends Applet {
  Button move;
  Random r;

  public void init() {
  move = new Button("Click me");
  r = new Random();
  public void paint(Graphics g){
  g.drawString("Welcome JSP-Applet",100,100);
  public boolean action(Event evt, Object whatAction) {
 if (!( instanceof Button))
 return false;
   String buttonLabel = (String)whatAction;
 if (buttonLabel == "Click me") {
  return true;

To use this applet we have used <jsp:plugin> in AppletJsp.jsp. This applet is being used in JSP file by the use of following code.

<jsp:plugin type="applet" code="ButtonMoveApplet.class" 
  width="400" height="400">
   <p>Unable to load applet</p>

Full code for AppletJsp.jsp is gievn as below:


<%@ page language="java" %>
<title>Welcome JSP-Applet Page</title>
<jsp:plugin type="applet" code="ButtonMoveApplet.class" 
  width="400" height="400">
   <p>Unable to load applet</p>

Steps for running this example:

  • Create and save
  • Compile and put its class file in your web folder(e.g Example in our case)
  • Create and save AppletJsp.jsp
  • Start tomcat server and type following URL in web browser:

You will get following output.


Download Source Code


Share on Google+Share on Google+

Using Applet in JSP

Posted on: July 8, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Using Applet in JSP   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
sunil kumar chaurasia
February 2, 2012

This is absolutely very good site.Here all the example are very excellent.
April 25, 2012
embed voice

Hi, I am working on a project which needs to give voice guidance. for ex: alert message should be spelt.if i click on submt button, it should say that form submitted.this project is mainly for blind people. Kindly do help me
May 6, 2012
how to include chat into JSP

I am a student I want to include chat in my JSP application. Please helpe me.
August 21, 2012
applet with jsp

this page is really useful for creating jsp project with the applet because give many features it features can be used