|
Source Code Archive
More Servlets and JavaServer Pages
Chapter 2: A Fast Introduction to Basic Servlet Programming
To view source code for other chapters in this book, mouse over the table of contents bar on the left.
Source Code from Chapter
Note: right-click or shift-click on the links to download the associated file.
- ServletTemplate.java.
Basic template for packageless servlet.
- HelloWorld.java.
Simple packageless servlet that generates plain text output.
- HelloServlet.java.
Simple packageless servlet that generates HTML output.
- HelloServlet2.java.
Simple servlet that demonstrates the use of packages. Remember to
put this and all remaining Chapter 2 classes in the moreservlets
directory.
- ServletUtilities.java.
A utility class that simplifies the generation of the
DOCTYPE and TITLE. Note:
most of the remaining servlets in this chapter use this class.
- HelloServlet3.java.
A servlet that uses the
ServletUtilities
class. If you get "unresolved symbol" errors when compiling this
servlet, review Section 1.6, especially the
CLASSPATH
settings on pages 19 and 20.
- web.xml.
Deployment descriptor illustrating how to set servlet initialization
parameters. See Chapter 5
for specific examples of the use of various
web.xml elements, including the setting of initialization
parameters for both servlets and JSP pages.
- ThreeParams.java.
Simple servlet that reads three parameters from the form data.
- ThreeParamsForm.html.
Form that sends data to the three-params servlet.
- ServletUtilities.java.
Same utility class shown earlier. The point here is the
filter
method that replaces the special HTML characters.
- ShowRequestHeaders.java.
Servlet that shows all the request headers sent in the current request.
- SearchEngines.java.
Servlet that takes a search string, number of results per
page, and a search engine name, sending the query to
that search engine. Illustrates manipulating
response status codes. Requires the
SearchSpec
and
ServletUtilities
classes.
- SearchSpec.java.
Small class that encapsulates how to construct a
search string for a particular search engine.
- SearchEngines.html.
Form that collects data for the search engine servlet.
- SetCookies.java.
Servlet that sets six cookies: three that apply only to the current
session (regardless of how long that session lasts)
and three that persist for an hour (regardless of
whether the browser is restarted).
- ShowCookies.java.
Servlet that creates a table of the cookies associated with
the current page.
- ServletUtilities.java.
Same utility class shown earlier. The point here is the
getCookieValue and getCookie
methods.
- LongLivedCookie.java.
Cookie that persists 1 year. Default cookie doesn't
persist past current session.
- ShowSession.java.
Simple example of session tracking.
- ShowItems.java.
Servlet that displays a list of items being ordered.
Accumulates them in an
ArrayList with no attempt at
detecting repeated items. Used to demonstrate basic
session tracking.
- OrderForm.html.
HTML form that collects values of the
newItem parameter
and submits them to the ShowItems servlet.
URLs Referenced in Chapter
More Information
-
J2EE training courses from the author. Available on-site at your
company or at public venues.
- Free online version of
Core Servlets & JavaServer Pages.
Complete text of book in PDF.
-
Home page for Core Servlets and JavaServer Pages 2nd Edition (Vol 1).
Includes the table of contents, index, sample chapters, source code archive, etc.
-
Home Page for More Servlets and JavaServer Pages.
Includes the table of contents, index, source code archive, etc.
-
Free online version of More Servlets and JavaServer Pages.
- Servlet and JSP Programming Resources.
Download sites, servers, IDEs, tutorials, books, job listings, and more.
-
Tutorials and lecture notes on servlets, JSP, Struts, JSF, and Java 5.
PDF version free for all. PowerPoint version free for qualified university instructors.
- Servlet and JSP
programming resources. Specs, documentation, servers, IDEs,
hosting providers, books, training, etc.
- Java Programming Resources.
General resources on Java technology. Compilers, editors, IDEs, tutorials, books,
user forums, and more.
|