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 5 Examples from Java Servlet Programming, 2nd Ed

  • 5-2: A servlet using buffering to support persistent connections
  • 5-3: Buffering
  • 5-4: Random redirector
  • 5-5: Where do you think you're going?
  • 5-6: The current time, kept current
  • 5-7: An explained host change
  • 5-11: Dynamically creating a general-purpose error page

Examples from other chapters:

Example 5.2: A servlet using buffering to support persistent connections
This servlet enables persistent connections (keep-alive) using the new built-in servlet ability to buffer its output.

Example 5.3: Buffering
This servlet shows how to use the reset() method to write and then clear content. It prints the default buffer size but to the log instead of the client so that it won’t be reset() away.

Example 5.4: Random redirector
This servlet performs a random redirect, sending a client to a random site selected from its site list. Depending on the site list, a servlet like this could have many uses. As it stands now, it's just a jump-off point to a selectino of cool servlet sites. With a site list containing advertising images, it can be used to select the next ad banner.

Example 5.5: Where do you think you're going?
Redirection can beused to learn where clients go when they leave your site. Assume you have several pages containing lists of links to other sites. Instead of linking directly to the external site, you can link to a redirecting servlet that can record each time an external link is selected. The HTML looks like this:
<a href="/goto/http://www.servlets.com">Servlets.com</a>
A servlet can beregistered to handle the /goto/* path prefix where it will receive the selected URL as extra path info and redirect the client to that location after making a note in the server log.servlet shows a servlet that uses client pull to display the current time, updated every 10 seconds.

Example 5.6: The current time, kept current
This servlet shows a servlet that uses client pull to display the current time, updated every 10 seconds.

Example 5.7: An explained host change
This servlet redirects requests for one host to another host, giving an exmplanation to the client before the redirection.

Example 5.11: Dynamically creating a general-purpose error page
This servlet acts as a general error display resource, supporting the display of both error status codes and exceptions. Note that under Microsoft Internet Explorer the error page from the server will be replaced by IE's own error message, losing the information the server is trying to provide you.

 


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