JSP actions mainly include the following:
1. <JSP: usebean>
Javabean is a special type of Java class. Compared with common Java classes, it has two special methods: Set... (Method for setting attributes), get... (Method for retrieving attribute values ).
<JSP: usebean> the action is used to find or instantiate the JavaBeans component used by a JSP page.
In a program, logical control and database operations can be placed in the JavaBeans component, and then called in the JSP file. This increases the definition of the program and the reusability of the program.
· Syntax:
<JSP: usebean id = "beaninstancename"
Scope = "Page | request | session | application"
Class = "package. claaa"
Type = "package. claaa"
Other elements
/>
· Attributes:
1) id = "beaninstancename"
The variable used to bind the bean instance.
2) Class | type = "package. claaa"
Specifies the class to which the bean is instantiated.
3) Scope = "Page | request | session | application"
The valid range of the bean.
Page: the effective range of the instance is the current page.
Request: The validity period of an instance is within the lifecycle of a single customer request.
Session: the effective range of the instance is within the entire user session lifecycle.
Application: the effective range of an instance is within the life cycle of the application.
2. <JSP: setproperty>
This action is used to set the values of one or more attributes using the set () method in bean. The source of the values is clearly given through the value attribute, or use the corresponding parameters in the request object.
Assume that a bean has a string-type property myproperty that can be used by JSP files, it must have a public method setmyproperty (string value), <JSP: setproperty> the Action uses this method.
· Syntax:
<JSP: setproperty name = "beaninstancename"
Property = "*" | property = "propertyname"
Value = "specific value"
/>
· Attributes:
1) name = "beaninstancename"
This attribute is required to indicate which bean instance to perform the following action. The value must correspond to the ID defined in the Action <JSP: usebean>, including the case sensitivity.
2) Property = "*" | property = "propertyname"
This attribute is required to indicate which attribute to set. If the property value is "*", it indicates all the values entered on the visible JSP page, which are stored in the matching bean property. The matching method is: the bean property name must be the same as the name in the input box.
3) value = "specific value"
It is used to specify the bean attribute value.
3. <JSP: getproperty>
This action extracts the value of the specified bean attribute, converts it to a string, and then outputs it. This action actually calls the get () method of bean.
As mentioned above, a bean has a string-type property myproperty that can be used by JSP files. It must have a public method getmyproperty () with the return type of string (). <JSP: getproperty> uses this method.
Syntax:
<JSP: getproperty name = "beaninstancename" property = "propertyname"/>
· Attributes:
1) name = "beaninstancename"
This attribute is required to indicate which bean instance to perform the following action. The value must correspond to the ID defined in the Action <JSP: usebean>, including the case sensitivity.
2) Property = "*" | property = "propertyname"
This attribute is required to indicate the attribute to be obtained.
· An example of using Java Bean in JSP
The code for test. jsp is as follows:
<HTML>
<Head>
<Title> test using Java Bean in JSP </title>
</Head>
<Body>
<JSP: usebean id = "test" class = "simlebean"/>
<JSP: setproperty name = "test" property = "message" value = "Hello jsp"/>
<P> message:
<JSP: getproperty name = "test" property = "message"/>
</Body>
</Html>
Explanation:
<JSP: usebean id = "test" class = "simlebean"/>: defines a Java Bean instance. The instance name is test and the class name is simlebean.
<JSP: setproperty name = "test" property = "message" value = "Hello jsp"/>: sets the message of the property of the test instance. The value is "Hello jsp ".
<JSP: getproperty name = "test" property = "message"/>: displays the value of the message property of the test instance on the page.
· The Java Bean code simplebean. java used in the test. jsp file is as follows:
Public class simplebean
{
Private string message;
Public String getmessage ()
{
Return message;
}
Public void setmessage (string message)
{
This. Message = message;
}
}
Note: The Blue section "message" in this Code indicates that the attribute name available in the JSP file is "message ".
4. <JSP: Include>
<JSP: Include> the action is to insert the body of other files into this program to increase the reusability and readability of the program.
· Syntax:
<JSP: Include page = "relativeurl" Flush = "true"/>
Or:
<JSP: Include page = "relativeurl" Flush = "true">
<JSP: Param name = "parametername" value = "parameter value"/>
</Jsp: Include>
· Attributes:
1) page = "relativeurl"
The relative path of the contained file.
2) flush = "true"
Generally, this attribute must be true.
3) <JSP: Param name = "parametername" value = "parameter value"/>
This statement allows one or more name/value pairs to be passed as parameters to the contained file.
5. <JSP: Forward>
<JSP: Forward> the action transfers the customer request to another page. <JSP: Forward> the following code is not executed.
· Syntax:
<JSP: Forward page = "relativeurl"/>
Or
<JSP: Forward page = "relativeurl">
<JSP: Param name = "parametername" value = "parameter value"/>
</Jsp: Forward>
· Attributes:
1) page = "relativeurl"
Jump to the relative path of the file.
2) <JSP: Param name = "parametername" value = "parameter value"/>
This statement allows one or more name/value pairs to be passed as parameters to the object to be jumped.
6. <JSP: plugin>
<JSP: plugin> the action is used to insert the object or embed elements required to run the Java Applet through the Java Plug-in based on the browser type.
· Syntax:
<JSP: plugin
Type = "bean | applet"
Code = "classfilename"
Codebase = "classfiledirectoryname"
[Name = "instancename"]
[Align = "bottom | top | Middle | left | right"]
[Height = "displsypixels"]
[Width = "displsypixels"]
[Hspace = "leftrightpixels"]
[Vspace = "topbuttompixels"]
[Jreversion = "Java version"]
[<JSP: Params>
[<JSP: Param name = "parametername" value = "parameter value"/>]
</Jsp: Params>]
[<JSP: fallback> the text information displayed to the user when the plug-in cannot be started </jsp: fallback>]
</Jsp: plugin>
· Attributes:
1) type = "bean | applet"
The type of the object to be executed by the plug-in, which must be specified.
2) code = "classfilename"
The name of the Java class file to be executed by the plug-in. The name must contain the extension, and the file must be in the directory specified by the "codebase" attribute.
3) codebase = "classfiledirectoryname"
Contains the directory of the Java class to be run by the plug-in or the path of the directory.
4) [name = "instancename"]
The bean or applet Instance name makes communication between beans or applets called by the same JSP file possible.
· <JSP: plugin> example
<HTML>
<Title> plugin example </title>
<Body>
The following insert a Java Applet <p>
<JSP: plugin type = "applet" code = "test. Class"
Codebase = "/examples/applet" jreversion = "2.0" width = 60 Height = 60>
<JSP: fallback> JAVA Applet cannot be run </jsp: fallback>
</Jsp: plugin>
</Body>
</Html>
Note: the blue part of the code inserts a Java Applet into the page. The class file name of this applet is "/examples/applet/test. class ", the height in the page is 60, and the width is 60.