Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Writing Enterprise Applications with Java™ 2 SDK, Enterprise Edition phần 8 ppt
Nội dung xem thử
Mô tả chi tiết
LESSON 5 ADDING JAVABEANS TECHNOLOGY TO THE MIX
83 SEPTEMBER 27, 2000
Getter methods follow the same naming conventions as setter methods so the JSP page can
retrieve data from the JBonusBean.Getter methods always have a return value and no arguments. You might notice that although the getBonusAmt method sets property values and
does not really need to return a value in this example, it returns this.bonusAmt to avoid a
runtime J2EE server error.
The getBonusAmt method uses an if-else statement to handle the case where no strMult
value is supplied. When the JSP page is first loaded, the end user has not supplied any data,
but all tags and scriptlets on the page are executed anyway. In this event, the data value for
the strMult property passed to JBonusBean is null, which results in a null multiplier and a
null bonusAmt value. A runtime server error occurs when the JSP page gets and tries to display the null bonusAmt value. To prevent this runtime error, bonusAmt is set to 0 in the event
a null strMult value is received from the JSP page.
public double getBonusAmt() {
if(strMult != null){
Integer integerMult = new Integer(strMult);
int multiplier = integerMult.intValue();
try {
double bonus = 100.00;
Calc theCalculation = homecalc.create();
Bonus theBonus = theCalculation.calcBonus(
multiplier, bonus, socsec);
Bonus record = theCalculation.getRecord(
socsec);
bonusAmt = record.getBonus();
socsec = record.getSocSec();
} catch (javax.ejb.DuplicateKeyException e) {
message = e.getMessage();
} catch (javax.ejb.CreateException e) {
e.printStackTrace();
} catch (java.rmi.RemoteException e) {
e.printStackTrace();
}
return this.bonusAmt;
} else {
this.bonusAmt = 0;
this.message = "None.";
return this.bonusAmt;
}
}
public String getMessage(){