In addition to the four tags seen in the previous sections, there is another special set of tags called the action tags. The use of the action tags was introduced primarily to make JSP more interactive with other components of a Web application. The use of action tags in your JSP makes writing a complete Web application easier. There are six action tags available. The following sections discuss each of these in detail. The usebean Action TagsThe usebean action tag is the most important action tag available: <jsp:usebean attribute1name=attribute1value attribute2name=attribute2value ... /> Using the usebean tag, you can embed entire Java objects within the JSP file. This makes the JSP cleaner, since you can use the embedded Java class like a bean and extract or set properties to the bean using accessor/mutator methods. The embedding of a Java bean within the JSP is an example of Model 1 architecture. In Model 1 architecture the JSP acts as the controller, handling browser requests, directing the flow of the application, and generating the output to the browser. The business logic, that is, the model in this architecture, is a set of Java classes that do the actual request processing and package the response for the view. The Java classes embedded in the usebean tag perform the same function. The id attribute is used to give a unique identifier to the Java bean embedded in the JSP. The value of the id attribute is the unique value that the developer defines. The scope attribute defines the scope of the Java bean embedded in the JSP. The scope attribute can have the following values:
The class attribute is used to define the actual Java class of which the bean is an instance. An instance of the Java class given as the value of this attribute is created by the JSP engine within WebLogic Server. If the class attribute is not used, no bean instance can be created. The type attribute is used to override the Java class type used when the bean was instantiated. Therefore, you can assign only a Java class type that is the superclass of the class used to instantiate the bean. If any other value is defined for the type attribute, the bean class will not be instantiated. The beanName attribute is used to define a Java class data type for the bean. The value of this attribute is a fully qualified package.class name for the Java class. This attribute is equivalent to the class attribute. The setProperty and getProperty Action TagsThe setProperty and getProperty tags are used in conjunction with the usebean tag to retrieve and set values in the embedded Java bean class. The setProperty tag is used as follows: <jsp:setProperty name="beanName" property="propertyname" value="propertyvalue"/> It has three attributes:
The getProperty tag is used as follows: <jsp:getProperty name="beanName" property="propertyname"/> It has two attributes:
The include Action TagThe include action tag is the XML equivalent of the include directive that you saw earlier. <jsp:include file="nameoffile"/> The forward Action Tag1The forward tag is used to perform communication between the JSP and a servlet or another JSP. The forward tag has one attribute: the page attribute. You can set a JSP filename or a servlet name as the value for the page attribute. The JSP engine uses this tag to delegate processing to the JSP or servlet specified as the value in the page attribute. <jsp:forward page="pagetobecalled"/> The plugin Action TagA less frequently used action tag is the plugin tag. The plugin tag is used to specify any embedded applets in the JSP page: <jsp:plugin attributename1=attributevalue1 attributename2=attributevalue2 .../> You can refer to the JSP specification 1.2 available on the java.sun.com Web site to find more information on JSP tags. |