10-05-2013, 04:27 PM
Jsaevravlets and JSP
Jsaevravlets.pdf (Size: 400.19 KB / Downloads: 21)
An introduction to web
programming with Java
This chapter introduces you to the concepts and terms that you need for
working with servlets and JavaServer Pages (JSPs) as you create web
applications. In particular, this chapter introduces you to the software that you
need to be able to write, deploy, and run servlets and JSPs.
A typical web application
Figure 1-1 shows the first two pages of the shopping cart application that’s
available from www.murach.com. Here, the first page presents some information
about our beginning Java book. This page contains two buttons: a View Cart
button and an Add To Cart button. When you click the Add To Cart button, the
web application adds the book to your cart and displays the second page in this
figure, which shows all of the items in your cart.
The second page lets you change the quantity for an item or remove an item
from the cart. It also lets you continue shopping or begin the checkout process.
In this book, you’ll learn all the skills you need to create a shopping cart application
like this one.
If you take a closer look at these web pages, you can learn a little bit about
how this application works. For the first page, the Address box of the browser
shows an address that has an htm extension. This means that the HTML code
for this page is probably stored in file with an htm extension.
In contrast, the Address box for the second page shows the address of a
servlet that was mapped to the cart/displayCart URL. This means that the
HTML code for this page was generated by the servlet. After the servlet address,
you can see a question mark and one parameter named productCode that
has a value of “jse6”. This is the parameter that was passed from the first page
The components of a web application
Figure 1-2 shows the basic components that make up a web application.
Because a web application is a type of client/server application, the components
of a web application are stored on either the client computer or the server
computer.
To access a web application, you use a web browser that runs on a client
computer. The most widely used web browser is Microsoft’s Internet Explorer,
and the most popular alternative is Mozilla Firefox.
The web application itself is stored on the server computer. This computer
runs web server software that enables it to send web pages to web browsers.
Although there are many web servers, the most popular one for Java web
applications is the Apache Software Foundation’s Apache HTTP Server, which
is usually just called Apache.
Because most web applications work with data that’s stored in a database,
most servers also run a database management system (DBMS). Two of the most
popular for Java development are Oracle and MySQL. Note, however, that the
DBMS doesn’t have to run on the same server as the web server software. In
fact, a separate database server is often used to improve an application’s overall
performance.
Description
• Web applications are a type of client/server application. In a client/server application, a
user at a client computer accesses an application at a server computer. For a web application,
the client and server computers are connected via the Internet or an intranet.
• In a web application, the user works with a web browser at the client computer. The web
browser provides the user interface for the application. The most widely used web
browser is Microsoft’s Internet Explorer, but other web browsers such as Mozilla Firefox
are also widely used.
• A web application runs on the server computer under the control of web server software.
For Java web applications, the Apache server is the most widely used web server.
• For most web applications, the server computer also runs a database management system
(DBMS). For servlet and JSP applications, Oracle and MySQL are two of the most
popular database management systems.
How dynamic web pages work
In contrast to a static web page, a dynamic web page changes based on the
parameters that are sent to the web application from another page. For instance,
when the Add To Cart button in the first page in figure 1-1 is clicked, the static
web page calls the web application and sends one parameter to it. Then, the web
application generates the dynamic web page and sends the HTML for it back to
the browser.
Figure 1-4 shows how this works. When a user enters data into a web page
and clicks the appropriate button, the browser sends an HTTP request to the
server. This request contains the address of the next web page along with any
data entered by the user. Then, when the web server receives this request and
determines that it is a request for a dynamic web page, it passes the request back
to the web application.
When the web application receives the request, it processes the data that the
user entered and generates an HTML document. Next, it sends that document to
the web server, which sends the document back to the browser in the form of an
HTTP response. Then, the browser displays the HTML document that’s included
in the response so the process can start over again.
The components of a Java web application
Figure 1-5 shows the primary software components for a Java web application.
By now, you should understand why the server must run web server
software. To run a Java application, though, the server must also run a software
product known as a servlet/JSP engine, or servlet/JSP container. This software
allows a web server to run servlets and JSPs.
Sun’s Java Enterprise Edition (Java EE) specification describes how a
servlet/JSP engine should interact with a web server. Since all servlet/JSP
engines must implement this specification, all servlet/JSP engines should work
similarly. In theory, this makes servlet/JSP code portable between servlet/JSP
engines and web servers. In practice, though, there are minor differences
between each servlet/JSP engine and web server. As a result, you may need to
make some modifications to your code when switching servlet/JSP engines or
web servers.