JSP syntax (6)

xiaoxiao2021-03-06  73

Set the attribute value in the bean.

JSP syntax

Name = "beaninstancename"

{

Property = "*" |

Property = "PropertyName" [param = "parametername"] |

Property = "PropertyName" Value = "{string | <% = expression%>}"

}

/>

example

description

Elements uses beans to set the setter method, set one or more attribute values ​​in the BEAN. You must use the to declare this bean before using this element. Because, and are associated, and the name of the Bean instance they use should also match. (That is to say, the value of Name in should be the same as the value of id in )

You can use a variety of ways to use to set the property value:

Match the properties in the bean by all values ​​entered by the user (in the Request object in parameter storage)

Match the attribute specified in the bean by the specified value input by the user.

Use an expression when running to match the properties of the bean

Each method of setting attribute values ​​has its specific syntax, below we will explain

Property and its usage

Name = "beaninstancename"

Represents the name of the bean instance created in .

Property = "*"

Store all values ​​for the user in the JSP input to match the properties in the bean. The name of the attribute in the bean must match the parameter name in the Request object.

The parameter values ​​transmitted from the customer to the player are generally character types, which must be converted to other types in the bean, and the type of bea property and their conversion method are listed in the table below.

Transform strings into other types of methods. Property type

method

Boolean or Boolean

Java.lang.Boolean.Valueof (String)

Byte or byte

Java.lang.byte.valueof (String)

Char or Character

Java.lang.Character.Valueof (String)

Double or DOUBLE

Java.lang.double.valueof (String)

Integer or Integer

Java.lang.integer.Valueof (String)

Float or float

Java.lang.float.Valueof (String)

Long or long

Java.lang.long.Valueof (String)

If there is an empty value in the parameter value of the Request object, the corresponding bean property will not set any values. Similarly, if there is an attribute in the bean without the corresponding request parameter value, then this attribute does not set .property = "PropertyName" [param = "parametername"]

Use a parameter value in the Request to specify an attribute value in the bean. In this syntax, Property specifies the property name of the bean, and param specifies the parameter name in the request.

If the bean property is different from the name of the request parameter, you must specify Property and Param if they are the same name, then you just need to indicate that Property is fine.

If the value is empty (or not initialized), the corresponding bean property is not set.

Property = "PropertyName" Value = "{string | <% = expression%>}"

Use the specified value to set the bean property. This value can be a string or an expression. If this string, it will be converted to the type of the bean property (see the above table). If it is an expression, then its type must be consistent with the type of attribute value to be set.

If the parameter value is empty, the corresponding attribute value will not be set. Also, you can't use Param and Value in a

skill

If you use Property = "*", then bean's properties are not necessary to sort in the order in the HTML form.

转载请注明原文地址:https://www.9cbs.com/read-92728.html

New Post(0)