How to use Action in JSP?

The plugin action is used to insert Java components into a JSP page. It determines the type of browser and inserts the <object> or <embed> tags as needed.

If the needed plugin is not present, it downloads the plugin and then executes the Java component. The Java component can be either an Applet or a JavaBean.

The plugin action has several attributes that correspond to common HTML tags used to format Java components. The <param> element can also be used to send parameters to the Applet or Bean.

Following is the typical syntax of using the plugin action −

<jsp:plugin type = "applet" codebase = "dirname" code = "MyApplet.class" width = "60" height = "80">
   <jsp:param name = "fontcolor" value = "red" />
   <jsp:param name = "background" value = "black" />

      Unable to initialize Java Plugin

You can try this action using some applet if you are interested. A new element, the <fallback> element, can be used to specify an error string to be sent to the user in case the component fails.

The <jsp:element> Action
The <jsp:attribute> Action
The <jsp:body> Action

The <jsp:element>, <jsp:attribute> and <jsp:body> actions are used to define XML elements dynamically. The word dynamically is important, because it means that the XML elements can be generated at request time rather than statically at compile time.

Following is a simple example to define XML elements dynamically −

<%@page language = "java" contentType = "text/html"%>
<html xmlns = "" xmlns:jsp = "">
   <head><title>Generate XML Element</title></head>
      <jsp:element name = "xmlElement">
         <jsp:attribute name = "xmlElementAttr">
            Value for the attribute
           Body for XML element

This would produce the following HTML code at run time −

<html xmlns = "" xmlns:jsp = "">
   <head><title>Generate XML Element</title></head>
      <xmlElement xmlElementAttr = "Value for the attribute">
         Body for XML element