Siêu thị PDFTải ngay đi em, trời tối mất

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 2 doc
MIỄN PHÍ
Số trang
14
Kích thước
126.5 KB
Định dạng
PDF
Lượt xem
1599

Writing Enterprise Applications with Java™ 2 SDK, Enterprise Edition phần 2 doc

Nội dung xem thử

Mô tả chi tiết

LESSON 1 A SIMPLE SESSION BEAN

SEPTEMBER 27, 2000 7

Import Statements

The servlet code begins with import statements for the following packages:

• javax.servlet, which contains generic (protocol-independent) servlet classes. The

HTTPServlet class uses the ServletException class in this package to indicate a

servlet problem.

• javax.servlet.http, which contains HTTP servlet classes. The HttpServlet class

is in this package.

• java.io for system input and output. The HttpServlet class uses the IOException

class in this package to signal that an input or output exception of some kind has

occurred.

• javax.naming for using the Java Naming and Directory Interface (JNDI) APIs to

look up the session bean home interface.

• javax.rmi for looking up the session bean home interface and making its remote

server object ready for communications.

init Method

The BonusServlet.init method looks up the session bean home interface and creates its

instance. The method uses the JNDI name specified during component assembly (calcs) to

get a reference to the home interface by its name. The next line passes the reference and the

home interface class to the PortableRemoteObject.narrow method to be sure the reference

can be cast to type CalcHome.

InitialContext ctx = new InitialContext();

Object objref = ctx.lookup("calcs");

homecalc = (CalcHome)PortableRemoteObject.narrow(obj

ref, CalcHome.class);

doGet Method

The parameter list for the doGet method takes a request and response object. The browser

sends a request to the servlet and the servlet sends a response back to the browser. The

method implementation accesses information in the request object to find out who made

the request, what form the request data is in, and which HTTP headers were sent, and uses

the response object to create an HTML page in response to the browser's request.

The doGet method throws an IOException if there is an input or output problem when it

handles the request, and a ServletException if the request could not be handled. To calcu￾late the bonus value, the doGet method creates the home interface and calls its calcBonus

method.

Tải ngay đi em, còn do dự, trời tối mất!