Java Reference
In-Depth Information
FIGURE 21.7
Using JSP and
Java objects to
count visits to a
web page.
Creating a Web Application
By combining Java classes, servlets, and JSP, you can create interactive web applica-
tions—sites that dynamically generate content in response to user input in a sophisti-
cated, cohesive way.
Every time you shop on an e-commerce site such as Amazon.com or use an online refer-
ence such as the Internet Movie Database (IMDB), you are running a web application.
To see how several aspects of Java technology can work together on the Web, you create
Guestbook , a web application that enables visitors to leave a message for the creator of a
site.
The Guestbook project is made up of three things:
guestbook.jsp —A JSP page that displays guestbook entries from a text file on a
web server and provides a form where a visitor can add an entry
n
guestbook-post.jsp —A page that saves a new guestbook entry to the text file
n
Guestbook.java —A class used to filter out some characters before they are saved
in the guestbook
n
The JSP page in this project makes heavy use of scriptlets and expressions. Listing 21.9
contains the source code for guestbook.jsp .
LISTING 21.9
The Full Text of guestbook.jsp
21
1: <%@ page import=”java.util.*,java.io.*” %>
2: <html>
3: <head>
4: <title>Visitors Who Signed our Guestbook</title>
5: </head>
6: <body>
Search WWH ::




Custom Search