Standard Action "jsp:plugin"


 

Standard Action "jsp:plugin"

In this Section, we will discuss about standard action "jsp:plugin" & their implementation using a example.

In this Section, we will discuss about standard action "jsp:plugin" & their implementation using a example.

Standard Action <jsp:plugin>

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"
            code="
classFileName"
            codebase="
classFileDirectoryName"
            [ height="
displayPixels" ]
            [ width="
displayPixels" ] [ <jsp:params>
            [ <jsp:params>
            name="
parameterName" value="parameterValue" /> ]+
            </jsp:params> ]
            [ <jsp:fallback>
text message for user </jsp:fallback> ]
            .........
            .........
            </jsp:plugin>


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>

    0

    </html>

     

    Pluginexample.java (Applet)

    1

    import java.awt.*;

    import java.applet.*;

    2

    public class Pluginexample extends Applet

    {

    // Specify variables that will be needed everywhere, anytime here

    3

    // The font variable

    Font bigFont;

    4

    // The colors you will use

    Color redColor;

    Color weirdColor;

    5

    Color bgColor;

    public void init()

    6

    {

    // Here we will define the varibles further

    // Will use Arial as type, 16 as size and bold as style

    7

    // Italic and Plain are also available

    bigFont = new Font("Arial",Font.BOLD,16);

    8

    // Standard colors can be named like this

    redColor = Color.red;

    9

    // lesser known colors can be made with R(ed)G(reen)B(lue).

    weirdColor = new Color(60,60,122);

    0

    bgColor = Color.blue;

    // this will set the backgroundcolor of the applet

    1

    setBackground(bgColor);

    }

    2

    public void stop()

    {

    3

    }

    // now lets draw things on screen

    4

    public void paint(Graphics g)

    {

    // tell g to use your font

    5

    g.setFont(bigFont);

    g.drawString("PLUGIN example",80,20);

    6

    // Now we tell g to change the color

    g.setColor(redColor);

    7

    // This will draw a rectangle (xco,yco,xwidth,height);

    g.drawRect(100,100,100,100);

    8

    // This will fill a rectangle

    g.fillRect(110,110,80,80);

    9

    // change colors again

    g.setColor(weirdColor);

    0

    // a circle (int x, int y, int width, int height,int startAngle, int arcAngle);

    // ovals are also possible this way.

    1

    g.fillArc(120,120,60,60,0,360);

    2

    g.setColor(Color.yellow);

    // Draw a line (int x1, int y1, int x2, int y2)

    3

    g.drawLine(140,140,160,160);

    4

    // 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.

    5

    g.setColor(Color. black);}

    }

    6

    OUTPUT :

    DOWNLOAD SOURCE CODE

    7

     

    Ads