Java培训 Bean getProperty 用法

1.useBean.jsp

 1 <jsp:useBean id="ib" class="Items.ItemBean" scope="page"/>
2
3 <jsp:setProperty property="numItems" name="ib" value="1000"/>
4 <jsp:setProperty property="unitCost" name="ib" value="25.00"/>
5
6 <html>
7 <head></head>
8 <body bgcolor="lemonchiffon">
9 <font size="+3">
10 <ul>
11 <li>Number of items:
12 <jsp:getProperty property="numItems" name="ib"/>
13 <li>Cost of each:
14 <jsp:getProperty property="unitCost" name="ib"/>
15 </ul>
16 </font>
17 </body>
18 </html>



2.ItemBean.java

 1 package Items;
2
3 public class ItemBean
4 {
5 private int numItems;
6 private float unitCost;
7
8 public ItemBean(
9 {
10 numItems = 10;
11 unitCost = 100.00f;
12 }
13 public int getNumItems()
14 {
15 return numItems;
16 }
17 public float getUnitCost()
18 {
19 return unitCost;
20 }
21 public void setNumItems(int iNumItems)
22 {
23 numItems = iNumItems;
24 }
25 public void setUnitCost(float fUnitCost)
26 {
27 unitCost = fUnitCost;
28 }
29 }

 

posted @ 2011-12-31 14:34  天涯行客  阅读(269)  评论(0编辑  收藏  举报
天道酬勤--埋头静默--厚积薄发