Đang chuẩn bị liên kết để tải về tài liệu:
Writing Enterprise Applications with Java™ 2 SDK, Enterprise Edition phần 4

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Click Finish. WAR tập tin hộp thoại Properties: • Click Next. Chọn phần hộp thoại Type: • Chọn Servlet (nếu nó chưa được chọn) • Kích Next. Hợp phần chung hộp thoại Properties: • Hãy chắc chắn rằng BonusServlet được chọn cho các lớp Servlet. LESSON 1 BEAN PHẦN SIMPLE | SEPTEMBER 27 2000 33 catch Exception NamingException NamingException.printStackTrace The try statement in the doGet method creates the CalcBean and BonusBean home interfaces. After calling calcBonus to calculate the bonus the BonusHome.create method is called to create an entity bean instance and a corresponding row in the underlying database table. After creating the table the BonusHome.findByPrimaryKey method is called to retrieve the same record by its primary key social security number . Next an HTML page is returned to the browser showing the data originally passed in the calculated bonus and the data retrieved from the database table row. The catch statement catches and handles duplicate primary key values social security numbers . The underlying database table cannot have two rows with the same primary key so if you pass in the same social security number the servlet catches and handles the error before trying to create the entity bean. In the event of a duplicate key the servlet returns an HTML page with the original data passed in the calculated bonus and a duplicate key error message. try Calc theCalculation Retrieve Bonus and Social Security Information String strMult request.getParameter MULTIPLIER Calculate bonus Integer integerMult new Integer strMult multiplier integerMult.intValue socsec request.getParameter SOCSEC Calculate bonus double bonus 100.00 theCalculation homecalc.create calc theCalculation.calcBonus multiplier bonus Create row in table theBonus homebonus.create calc socsec record homebonus.findByPrimaryKey socsec Display data out.println H1 Bonus Calculation H1 out.println P Soc Sec passed in theBonus.getSocSec P out.println P Multiplier passed in multiplier P out.println P Bonus Amount calculated theBonus.getBonus P out.println P Soc Sec retrieved record.getSocSec P out.println P Bonus Amount retrieved LESSON 2 A SIMPLE ENTITY BEAN 34 SEPTEMBER 27 2000 record.getBonus P out.println BODY HTML Catch duplicate key error catch .