<jsp:setProperty><br>
Sets a property value or values in a Bean. <br>
<br>
JSP syntax<br>
<jsp:setproperty <br>
Name= "Beaninstancename" <br>
{<br>
property= "*" | <br>
property= "PropertyName" [param= "ParameterName"] | <br>
Property= "PropertyName" value= "{string | <%= expression%>}" <br>
} <br>
/> <br>
Examples<br>
<jsp:setproperty name= "Mybean" property= "*"/> <br>
<jsp:setproperty name= "Mybean" property= "username"/> <br>
<jsp:setproperty name= "Mybean" property= "username" value= "Steve"/> <br>
Description<br>
The <jsp:setProperty> element sets the value of one or more properties in a bean, the using the bean ' s setter methods. You must declare the beans with <jsp:useBean> before your set a property value with <jsp:setproperty>. Because <jsp:useBean> and <jsp:setProperty> work together, the Bean instance names they use must match s, the value of name in <jsp:setProperty> and the value of ID in <jsp:useBean> must is the same). <br>
<br>
Can <jsp:setProperty> to set property values in several ways: <br>
<br>
By passing all of the values the user enters (stored as parameters in the request object) to matching properties in the An <br>
By passing a specific value of the user enters to a specific property in the Bean <br>
By setting a Bean property to a value you specify as either a String or a expression this is evaluated at runtime <br& Gt
The setting property values has it own syntax, as described in the next section. <br>
<br>
Attributes and Usage<br>
Name= "Beaninstancename" <br>
The name of an instance of a Bean this has already been created or located with a <jsp:useBean> element. The value of name must match the value of ID in <jsp:usebean>. The <jsp:useBean> element must appear before <jsp:seProperty> in the JSP file. <br>
<br>
property= "*" <br>
Stores all of the values the "user enters in" viewable JSP page (called request parameters) in matching Bean properties. The names of the properties in the Bean must match the names of the request parameters, which are usually the elements of An HTML form. A Bean property was usually defined by a variable declaration with matching getter and setter methods (for more information , the JavaBeans API specification available at Http://java.sun.com/beans). <br>
<br>
The values of the request parameters sent from the client to the server are always of type String. The String values are converted to other data types so they can is stored in Bean properties. The allowed Bean property types and their conversion methods are in TABLE 1-1. <br>
<br>
How <jsp:setProperty> converts Strings to other Values <br>
<br>
Property Type <br>
<br>
<br>
String is converted Using <br>
<br>
<br>
<br>
Boolean or Boolean <br>
<br>
<br>
Java.lang.Boolean.valueOf (String) <br>
<br>
<br>
<br>
byte or byte <br>
<br>
<br>
Java.lang.Byte.valueOf (String) <br>
<br>
<br>
<br>
char or Character <br>
<br>
<br>
Java.lang.Character.valueOf (String) <br>
<br>
<br>
<br>
Double or double <br>
<br>
<br>
Java.lang.Double.valueOf (String) <br>
<br>
<br>
<br>
Integer or integer <br>
<br>
<br>
Java.lang.Integer.valueOf (String) <br>
<br>
<br>
<br>
float or float <br>
<br>
<br>
Java.lang.Float.valueOf (String) <br>
<br>
<br>
<br>
Long or long <br>
<br>
<br>
Java.lang.Long.valueOf (String) <br>
<br>
<br>
<br>
<br>
You can also use <jsp:setProperty> to set the value of a indexed a Bean. The indexed property must is an array of one of the data types shown in TABLE 1-1. The array elements are converted using the conversion methods shown in the table. <br>
<br>
If A request parameter has a empty or null value, the corresponding Bean property is not set. Likewise, if the Bean has a property this does not have a matching request parameter, the property value is not set. <br>
<br>
property= "PropertyName" [param= "ParameterName"] <br>
Sets one Bean to the value of one request parameter. In the syntax, the property specifies the name of the Beans property and param specifies the ' name of the ' request parameter by W The hich data is being sent from the client to the server. <br>
<br>
If the Bean property and the request parameter have different names, you must specify and both. If they have the same name, you can specify property and omit Param. <br>
<br>
If A parameter has a empty or null value, the corresponding Bean property is not set. <br>
<br>
Property= "PropertyName" value= "{string | <%= expression%>}" <br>
Sets one Bean property to a specific value. The value can be a String or a expression this is evaluated at runtime. If The value is a String, it's converted to the Bean property ' s data type according to the conversion rules shown above I N TABLE 1-1. If It is a expression, its value must have a data type that matches the data type of the expression must Match the data type of the Bean property. <br>
<br>
If The parameter has a empty or null value, the corresponding Bean property is not set. You are cannot use both the Param and value attributes in a <jsp:setProperty> element. <br>
<br>
Also<br>
<jsp:useBean> <br>
<jsp:getProperty> <br>
Tips<br>
When with property= "*", the Bean properties are not necessarily set in which they appear in the HTML form or the Bean. <br>
In Sun's JSP 1.0 or JSP 1.1 Tomcat, the Bean properties are set in the order of which they are to the JSP presented NER by the Beans Introspector. If the order in which the properties are set are important to how your Bean works, use the syntax form property= "Propertyna Me "[param=" ParameterName "]. Better yet, rewrite your Bean so this order of setting properties are not important. <br>
<br>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.