The JSP action has the following six: 1, JavaBean is a special type of Java class, which compares to the normal Java class to include two special ways: set ... (Method for setting attributes), Get ... (Method for taking the attribute value). Action is used to find or instantiate a JavaBeans component used by a JSP page. In the program, logic control, database operations are placed in the JavaBeans component, then call it in the JSP file, which increases the clarity of the program and the reusability of the program.
The syntax is as follows: · Property: 1) ID = " "BeanInstanceName" used to bind the variables of the bean instance. 2) Class | Type = "package.claaa" indicates which class is instantiated. 3) Scope = "Page | Request | Session | Application" indicates a valid range of the bean. Page: The effective range of the instance is the current page. The REQUEST: The effective range of the instance is within the life cycle of a separate customer request. Session: The effective range of the instance is within the life cycle of the entire user session. Application: The effective range of the instance is within the life cycle of the application.
2, The meaning of this action is to use the corresponding set () method in the bean to set the value of one or more attributes, and the source of the value is explicitly given by the value attribute, or the corresponding parameters in the Request object. Assuming a bean has a String type with the property MyProperty that can be used by the JSP file, it must have a public method setMyProperty (String value), The method is used. The syntax is as follows: · Property: 1) Name = "beaninstancename" This property is necessary, used To indicate which bean instance executes the following action, this value and action must correspond to, including case, must be consistent. 2) Property = "*" | Property = "PropertyName" This attribute is required to indicate which property you want to set. If the value of the Property is "*", it means that the user enters all values in the visible JSP page, stored in the matching bean property. The matching method is: The attribute name of the bean must be the same as the name of the input box. 3) Value = "Specific value" It is used to specify the value of the properties of the bean.
3, This action extracts the value of the specified bean property, converts into a string, and then output. This action is actually calling the get () method of the bean. According to a bean mentioned above, there is a String type of the property MYPROPERTY that can be used by the JSP file, which must have a returned PUBLIC method getMyProperty (). It is this method. The syntax is as follows: · Property: 1) Name = "beanting" This property is required, to indicate which bean instance performs the following action, this value and The ID defined in the action must correspond to, including case, both must be consistent. 2) Property = "*" | Property = "PropertyName" This attribute is required to indicate which property to get. • One example of using JAVA bean in JSP is as follows: JSP Using Java Bean's test title> head> message: body> html> explanation: : Indicates an instance of a Java Bean, the name of the instance is Test, the name of the class is SimleBean. : Indicates the properties of the set instance Test Message, which is "Hello JSP". : Indicates the value of the property Message that outputs the instance TEST in the page. · Java bean's code used in Test.jsp file SimpleBean.java as follows: Public class simplebean {private string message; public string getMessage () {Return Message;}
Public void setment {this.Message = message;}} Note: The blue section "Message" in this code indicates that the attribute name that can be used in the JSP file is "Message".
4, The purpose of the action is to insert the body of other files into this program to increase the reusability and readability of the program. · Syntax: or: jsp: Include> · Property: 1) Page =" relativeurl "is included with the relative path of the file. 2) Flush = "true" is usually in the case, this property must be true. 3) This sentence allows one or more names / values to be transmitted to the included files as parameters. 5, Action forwards the customer request to another page, The following code will not be executed. · Syntax: or jsp: Forward> · Property: 1) Page = "relativeURL" to jump to the relative path of the file. 2) This sentence allows one or more names / values to be transmitted as a parameter to a file.
6, Action is used to insert an Object or an Embed element that runs the Java Applet through the Java plugin according to the type of browser. * Syntax: ] jsp: params>] [ This is displayed to the user's text information jsp: Fallback>] jsp: plugin> · Properties: 1) Type = "bean | applet" plugin The type of object will be executed, must be specified. 2) Code = "ClassFileName" plugin will execute the name of the Java class file, must contain the extension in the name, and this file must be in the directory specified by the "CodeBase" property. 3) CodeBase = "classfileDirectoryName" contains a directory of the plugin to run the Java class or a path to this directory. 4) [Name = "InstanceName"] bean or applet's instance of the instance of the instance, making communication between the bean or applet called the same JSP file called.
· Example Plugin Example title> The following will insert a Java Applet Cannot run java applet jsp: Fallback> jsp: plugin> body> html> Note: Blue Part of the code will insert a Java Applet in the page, the applet class file name is "/examples/applet/test.class", the high is 60 in the page, and the width is 60.