Home
What's
New?
com.oreilly.servlet
Servlet
Polls
Mailing
Lists
Servlet
Engines
Servlet
ISPs
Servlet
Tools
Documentation
Online
Articles
The
Soapbox
"Java
Servlet
Programming,
Second Edition"
"Java
Enterprise
Best Practices"
Speaking
& Slides
About
Jason
XQuery
Affiliate
Advertising
Info
|
Chapter 6 Examples from Java Servlet
Programming, 2nd Ed
- 6-1: A WML minibartender, drinks.wml
- 6-4 and 6-5: Using WML to ask for an
area code
- 6-6: Hello World graphics
- 6-7: A chart comparing applets and oranges
- 6-8: Drawing over an image to mark it
confidential
- 6-9: Combining images to form a graphical
counter
- 6-10: An image effect converting an image
to grayscale
- 6-12: Sending compressed content
- 6-13: Countdown to a rocket launch
Examples from other chapters:
- Example 6.1: A WML minibartender, drinks.wml
- This example is not a servlet. It's a static WML document that
acts as a minibartender with dynamic qualities built into the
WML. The example provides a list of drinks to choose from, then
displays the ingredients of the selected drink. Notice the document
is XML with a well-known DTD.
- Try it (Requires a phone simulator,
see the book)
- Source (WML with an XML extension)
- Source (web.xml)
- Example 6.4 and 6.5: Using WML to ask for an area code
- This WML file and servlet demonstrate anarea code lookup application.
A client may enter a telephone area code into the form, submit
it to the servlet, and learn which state or region contains that
code. People with WAP-enabled phones can use this application
to physically locate any Caller ID number.
- Try it (Requires a phone simulator,
see the book)
- Source (WML with an XML extension)
- Source (Supporting servlet)
- Example 6.6: Hello World graphics
- This servlet generates and returns a GIF image. The graphic
says "Hello World!"
- Example 6.7: A chart comparing applets and oranges
- This servlet creates a bar chart that compares apples to oranges,
with regard to their annual consumption. There's little need for
this chart to be dynamically generated, but it lets us get the
point across without too much code. Picture in your mind's eye
that the servlet is charting up-to-the-minute stock values or
the server's recent load.
- Example 6.8: Drawing over an image to mark it confidential
- This servlet writes "CONFIDENTIAL" over every image it returns.
The image name is passed to the servlet as extra path information.
- Example 6.9: Combining images to form a graphical counter
- This servlet displays a hit count as a sequence of individual
number images combined into one large image.
- Example 6.10: An image effect converting an image to grayscale
- This servlet shows a servlet that converts an image to grayscale
before returning it. The servlet performs this effect without
ever actually creating an off-screen graphics context. Instead,
it creates the image using a special ImageFilter.
- Example 6.12: Sending compressed content
- This servlet is the ViewResource servlet from Chapter 4 rewritten
to send compressed content whenever possible. An end user cannot
tell that the server sent compressed content to the browser--except
perhaps with reduced download times. It's disabled because the
servlet would happily serve any files from this site.
- Try it (disabled for security)
- Source
- Example 6.13: Countdown to a rocket launch
- This servlet uses server push to display a countdown to a rocket
launch. It begins by sending a series of pages that count down
from 10 to 1. Every page replaces the previous page. When the
countdown reaches 0, the servlet sends a picture of a launch.
It uses the com.oreilly.servlet.MultipartResponse utility class
to manage the server push details. This example does not work
with Microsoft Internet Explorer nor with Netscape Navigator 6.
IE doesn't support server push and NN6 has severe bugs in this
area. Mozilla/Firefox is your best bet.
|