In this Section, we will discuss about standard action "jsp:plugin" & their implementation using a example.
The <jsp:plugin> action is use to download a plugin (an Applet or a Bean) to
the client Web browser to execute it. The <jsp:plugin> tag is
replaced by either an <object> or <embed> tag,
whichever is most appropriate for the client Web browser (the <object>
tag is for browsers that use HTML 4.0). The <jsp:params> element
sends parameter names and values to an applet or Bean at startup. The <jsp:fallback>
element provides a message for the user if the plugin does not start. If the
plugin starts but the applet or Bean does not, the plugin usually displays a
popup window explaining the error to the user.
Syntax :
<jsp:plugin
type="bean|applet" classFileName"
classFileDirectoryName"
displayPixels" ]
displayPixels" ]
[ <jsp:params> parameterName" value="parameterValue" /> ]+
text message for user </jsp:fallback> ]
|
Description :
type="bean|applet"
The type of object the plugin will execute. You must
specify either bean or applet, as this attribute has
no default value.
code="classFileName"
The name of the Java class file that the plugin will
execute. You must include the .class extension in the name following code.
The filename is relative to the directory named in the codebase
attribute.
codebase="classFileDirectoryName"
The absolute or relative path to the directory that
contains the applet's code. If you do not supply a value, the path of
the JSP file that calls <jsp:plugin>
is used.
height="displayPixels" width="displayPixels"
The initial height and width, in pixels, of the image the applet or Bean displays, not counting any windows or dialog boxes the applet or Bean brings up.
<jsp:params> [ <jsp:param name="parameterName"
value="parameterValue" /> ]+ </jsp:params>
The parameters and values that you want to pass to
the applet or Bean. To specify more than one name and value, use multiple
<jsp:param> tags within the <jsp:params> element.
Applets read parameters with the java.applet.Applet.getParameter
method.
<jsp:fallback> text message for user </jsp:fallback>
A text message to display for the user if the plugin cannot be started.
EXAMPLE:
In this example, we are going to insert the "Pluginexample.java" Applet into the "Pluginstandardaction.jsp" file using '<jsp:plugin>' standard action.
pluginstandardaction.jsp
|
< html>< title> Plugin example </title>< body bgcolor="white">< h3> The given below applet is imported to this file : </h3>< jsp:plugin type="applet" code="Pluginexample.class" codebase="applet"height="300" width="300"> <jsp:fallback>Plugin tag not supported by browser. </jsp:fallback></ jsp:plugin>< h4><font color=red>The above applet is loaded using the Java Plugin from a jsp page using the plugin tag. </ font></ h4></ body></ html>
|
Pluginexample.java (Applet)
|
import java.awt.*;import java.applet.*;public class Pluginexample extends Applet{ // Specify variables that will be needed everywhere, anytime here // The font variableFont bigFont;// The colors you will use Color redColor;Color weirdColor;Color bgColor; public void init(){ // Here we will define the varibles further // Will use Arial as type, 16 as size and bold as style // Italic and Plain are also available bigFont = new Font("Arial",Font.BOLD,16); // Standard colors can be named like this redColor = Color.red; // lesser known colors can be made with R(ed)G(reen)B(lue). weirdColor = new Color(60,60,122); bgColor = Color.blue; // this will set the backgroundcolor of the appletsetBackground( bgColor);} public void stop(){ } // now lets draw things on screen public void paint(Graphics g){ // tell g to use your fontg.setFont( bigFont);g.drawString( "PLUGIN example",80,20); // Now we tell g to change the colorg.setColor( redColor); // This will draw a rectangle (xco,yco,xwidth,height);g.drawRect(100,100,100,100); // This will fill a rectangleg.fillRect(110,110,80,80); // change colors againg.setColor( weirdColor); // a circle (int x, int y, int width, int height,int startAngle, int arcAngle); // ovals are also possible this way.g.fillArc(120,120,60,60,0,360); g.setColor(Color. yellow); // Draw a line (int x1, int y1, int x2, int y2)g.drawLine(140,140,160,160); // reset the color to the standard color for the next time the applets paints // an applet is repainted when a part was'nt visible anymore // happens most often because of browser minimizing or scrolling.g.setColor(Color. black);}} |
OUTPUT :

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.