Java培训 Bean getProperty 用法

1.useBean.jsp

 1 <jsp:useBean id="ib" class="Items.ItemBean" scope="page"/>
2 <html>
3 <head></head>
4 <body bgcolor="lemonchiffon">
5 <font size="+3">
6 <ul>
7 <li>Number of items:
8 <jsp:getProperty property="numItems" name="ib"/>
9 <li>Cost of each:
10 <jsp:getProperty property="unitCost" name="ib"/>
11 </ul>
12 </font>
13 </body>
14 </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:07  天涯行客  阅读(228)  评论(0编辑  收藏  举报
天道酬勤--埋头静默--厚积薄发