当前位置: 首页 > 图文教程 > 网络编程 > JSP > 讲一讲setproperty(name="*")的用法或介绍相关资料

JSP
客户端界面中可视化的实现树形框架的设计
Win2000下JBoss开发环境配置
调试处理系统核心文件
Matrix java 大讲坛 之 可用性与人机界面
JMX调试----第三方工具使访问更加容易
用BSF如何在Java中嵌入javascript以及如何在javascript中
再次提醒\" 请不要做浮躁的人\"
从Coding Fan到真正的技术专家(cjsdn)
数据库BEAN:RESIN连接池
基于Java的Web服务器工作原理(一)
XDE中模式驱动的设计与开发(三)
页面流(Page flow)表单验证
高级页面流(Page flow):嵌套、异常处理和 Global.app
请不要做浮躁的人(ZT-必读)
解决日期选择问题,一劳永逸(使用Decorator模式实现日期选择组件)(二)
解决日期选择问题,一劳永逸(使用Decorator模式实现日期选择组件)(三)
解决日期选择问题,一劳永逸(使用Decorator模式实现日期选择组件)(四)
解决日期选择问题,一劳永逸(使用Decorator模式实现日期选择组件)(五)
EJB技术之旅(一)
MVC渐行渐进(二)

JSP 中的 讲一讲setproperty(name="*")的用法或介绍相关资料


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-04   浏览: 368 ::
收藏到网摘: n/a

&lt;jsp:setProperty&gt;<br>
Sets a property value or values in a Bean. <br>
<br>
JSP Syntax<br>
&lt;jsp:setProperty <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name=&quot;beanInstanceName&quot; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property= &quot;*&quot;&nbsp;&nbsp;&nbsp;| <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property=&quot;propertyName&quot; [ param=&quot;parameterName&quot; ]&nbsp;&nbsp;&nbsp;| <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property=&quot;propertyName&quot; value=&quot;{string | &lt;%= expression %&gt;}&quot; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br>
/&gt; <br>
Examples<br>
&lt;jsp:setProperty name=&quot;mybean&quot; property=&quot;*&quot; /&gt; <br>
&lt;jsp:setProperty name=&quot;mybean&quot; property=&quot;username&quot; /&gt; <br>
&lt;jsp:setProperty name=&quot;mybean&quot; property=&quot;username&quot; value=&quot;Steve&quot; /&gt; <br>
Description<br>
The &lt;jsp:setProperty&gt; element sets the value of one or more properties in a Bean, using the Bean's setter methods. You must declare the Bean with &lt;jsp:useBean&gt; before you set a property value with &lt;jsp:setProperty&gt;. Because &lt;jsp:useBean&gt; and &lt;jsp:setProperty&gt; work together, the Bean instance names they use must match (that is, the value of name in &lt;jsp:setProperty&gt; and the value of id in &lt;jsp:useBean&gt; must be the same). <br>
<br>
You can use &lt;jsp:setProperty&gt; 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 Bean <br>
By passing a specific value 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 an expression that is evaluated at runtime <br>
Each method of setting property values has its own syntax, as described in the next section. <br>
<br>
Attributes and Usage<br>
name=&quot;beanInstanceName&quot; <br>
The name of an instance of a Bean that has already been created or located with a &lt;jsp:useBean&gt; element. The value of name must match the value of id in &lt;jsp:useBean&gt;. The &lt;jsp:useBean&gt; element must appear before &lt;jsp:seProperty&gt; in the JSP file. <br>
<br>
property=&quot;*&quot; <br>
Stores all of the values the user enters in the 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 is usually defined by a variable declaration with matching getter and setter methods (for more information, see 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 be stored in Bean properties. The allowed Bean property types and their conversion methods are shown in TABLE 1-1. <br>
<br>
How &lt;jsp:setProperty&gt; Converts Strings to Other Values&nbsp;&nbsp;<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 &lt;jsp:setProperty&gt; to set the value of an indexed property in a Bean. The indexed property must be 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 an empty or null value, the corresponding Bean property is not set. Likewise, if the Bean has a property that does not have a matching request parameter, the property value is not set. <br>
<br>
property=&quot;propertyName&quot; [ param=&quot;parameterName&quot; ] <br>
Sets one Bean property to the value of one request parameter. In the syntax, property specifies the name of the Bean property and param specifies the name of the request parameter by which 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 both property and param. If they have the same name, you can specify property and omit param. <br>
<br>
If a parameter has an empty or null value, the corresponding Bean property is not set. <br>
<br>
property=&quot;propertyName&quot; value=&quot;{string | &lt;%= expression %&gt;}&quot; <br>
Sets one Bean property to a specific value. The value can be a String or an expression that is evaluated at runtime. If the value is a String, it is converted to the Bean property's data type according to the conversion rules shown above in TABLE 1-1. If it is an expression, its value must have a data type that matches the the data type of the value of the expression must match the data type of the Bean property. <br>
<br>
If the parameter has an empty or null value, the corresponding Bean property is not set. You cannot use both the param and value attributes in a &lt;jsp:setProperty&gt; element. <br>
<br>
See Also<br>
&lt;jsp:useBean&gt; <br>
&lt;jsp:getProperty&gt; <br>
Tips<br>
When you use property=&quot;*&quot;, the Bean properties are not necessarily set in the order 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 in which they are presented to the JSP container by the Beans introspector. If the order in which the properties are set is important to how your Bean works, use the syntax form property=&quot;propertyName&quot; [ param=&quot;parameterName&quot; ]. Better yet, rewrite your Bean so that the order of setting properties is not important. <br>
<br>