Java Reference
In-Depth Information
19.5
Web Programming with Java Server Pages
Everything is connected… no one thing can change by itself.
PAUL HAWKEN
Up to this point, we have used Java to create stand-alone applications. However,
Java is also used to create interactive websites. In this section, we briefly introduce
ways that Java can be used on the Web with an emphasis on Java Server Pages. This
section requires a basic understanding of HTML. An introduction to HTML is given
in Chapter 20, which is included on the website with this topic. This section is not
a complete enough introduction to allow you to immediately start writing Java Web
applications. The intent is to introduce the major concepts behind Java Server Pages so
you can learn what kinds of things are possible should you wish to learn more with a
book or other resource dedicated to the topic.
Applets, Servlets, and Java Server Pages
When you instruct your Web browser to view a page from a Web server on the Internet,
your Web browser requests the page from the Web server, the Web server processes the
request (which may involve reading the requested page from a file on the hard drive),
and then the Web server sends the requested page to your Web browser. Your Web
browser formats, or renders, the received data to fit on your computer screen. This
interaction is a specific case of the client/server model described in Section 19.2. Your
Web browser is the client program, your computer is the client computer, the remote
website is the server computer (e.g., http://www.remotesite.com), and the Web server
software running on the remote website is the server program.
In the context of a Web application, the client/server model is important because
Java code can run in two places: on the client or on the server. There are trade-offs to
both approaches. Server-based programs have easy access to information that resides on
the server, such as customer orders or inventory data. Because all of the computation is
done on the server and results are transmitted to the client as HTML, a client does not
need a powerful computer to run a server-based program. On the other hand, a client-
based program may require a more powerful client computer, because all computation
is performed locally. However, richer interaction is possible, because the client program
has access to local resources, such as the graphics display (e.g., perhaps using Swing) or
the operating system. Many systems today are constructed using code that runs on
both the client and the server to reap the benefit of both approaches.
Web applications built with Java include Java applets , Java servlets , and Java
Server Pages ( JSP ) . Java applets run on the client computer and are discussed in
Chapter 20. JavaScript, which is a different language than Java despite its similar
name, also runs on the client computer as part of the Web browser. Java servlets and
Java Server Pages run on the server. In this chapter, we focus primarily on Java Server
Pages, which are a dynamic version of Java servlets. Servlets must be compiled before
they can run, just like a normal Java program. In contrast, JSP code is embedded with
Java applet
Java servlet
Java Server
Pages
 
 
Search WWH ::




Custom Search