Java Reference
In-Depth Information
Servlets
A third use of Java is to create servlets. A servlet is a Java program that is
hosted and run on a Web server rather than launched from a browser. Hosting
involves storing Web pages, programs, and other data on a computer that a user
connects via a network, intranet, or the Web. A Web server is a computer that
hosts Web pages, programs, and other files, which it delivers or serves to request-
ing computers. Web servers use server software that responds to incoming
requests and serves different forms of data, as well as interfacing with applica-
tions and servlets. Thus, servlets are considered to be server-side , because the
programs are hosted and run on the server and are not executed on the client, as
are applets (Figure 1-5).
1. Request for balances over $1,000
3. Servlet returns customer records with balances ov
er $1,000
4. Requesting client
computer prepares r eport
2. Server selects c ustomers
with balances ove r $1,000
FIGURE 1-5
Servlets now are widely used to extend Web server and database functional-
ity. Servlets can be used with Java Server Pages ( JSP ), a server-side technology
that extends the Java servlet technology to provide a way to create sophisticated
solutions that run on any platform. JSP, when used with servlets, separates the
display logic on the client machine (for example, how a Web page or program
displays to a user) from the business logic on the server (the rules that define
program calculations, responses, and so on). Upon first use, a JSP page is trans-
lated into Java source code, which is then compiled into a class file. From then
on, it runs similar to any other servlet unless the original JSP file is changed.
Another common use of Java servlets is to connect to databases using Java
Database Connectivity ( JDBC ), a Java interface that enables Java applications to
execute queries and interact with most databases.
Search WWH ::




Custom Search