Servlets.com

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

The Book
Chapter 6 Examples from Java Servlet Programming

  • 6-1: Hello World graphics
  • 6-2: A chart comparing applets and oranges
  • 6-3: Drawing over an image to mark it confidential
  • 6-4: Combining images to form a graphical counter
  • 6-5: An image effect converting an image to grayscale
  • 6-9: Embedding SecondApplet
  • 6-10: A generic applet viewer
  • 6-11: Sending compressed content
  • 6-12: Countdown to a rocket launch

Examples from other chapters:


Example 6.1: Hello World graphics
This servlet generates and returns a GIF image. The graphic says "Hello World!"

Example 6.2: 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.3: 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.4: 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.5: 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.9: Embedding SecondApplet
This servlet embeds SecondApplet inside itself and sends a picture of the applet to the client. It uses a modified version of Jef Poskanzer's Acme.MainFrame class, available in example code JAR. The fonts can appear weird depending on the system fonts installed.

Example 6.10: A generic applet viewer
This servlet is a servlet capable of embedding and taking a picture of any applet. It can accept as request parameter the applet name, its width and height, and its parameters.

Example 6.11: Sending compressed content
This servlet is the ViewFile 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.12: 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.

 


Home   com.oreilly.servlet   Polls   Lists   
Engines   ISPs   Tools   Docs   Articles   Soapbox   Book

Copyright © 1999-2005 Jason Hunter
Privacy Policy

webmaster@servlets.com
Last updated: March 1, 2009