What's New?


Servlet Polls

Mailing Lists

Servlet Engines

Servlet ISPs

Servlet Tools


Online Articles

The Soapbox

"Java Servlet
Second Edition"

"Java Enterprise
Best Practices"

Speaking & Slides

About Jason

XQuery Affiliate

Advertising Info

The Book
Chapter 4 Examples from Java Servlet Programming, 2nd Ed

  • 4-2: Getting init parameter names
  • 4-3: Snooping the server
  • 4-5: A servlet locked to a server
  • 4-9: Snooping versions
  • 4-10: Can they be trusted?
  • 4-11: Hey, I remember you!
  • 4-12: Snooping parameters
  • 4-13: Unlocking KeyedServerLock
  • 4-14: Showing where the path leads
  • 4-16: Dynamically returning static files
  • 4-18: Serving an abstract resource, safely
  • 4-19: Snooping headers
  • 4-21: Handling a file upload

Examples from other chapters:

Example 4.2: Getting init parameter names
This servlet prints the name and value for all of its init parameters.

Example 4.3: Snooping the server
This servlet displays information about its server.

Example 4.5: A servlet locked to a server
This servlet locks itself to a particular server IP address and port number. It requires an init parameter key that is appropriate for its servet IP address and port before it unlocks itself and handles a request. It's unlocked via the servlet in Example 4.8.

Example 4.9: Snooping versions
This servlet snoops the server's servlet and Java version.

Example 4.10: Can they be trusted?
This servlet checks the client machine and only allows access if the client appears to be coming from somewhere other than the Terrorist 7 countries. A servlet like this could help restrict the export of strong encryption.

Example 4.11: Hey, I remember you!
This servlet greets its clients by name and remembers when each last logged in.

Example 4.12: Snooping parameters
This servlet prints its query string, then prints the name and value for all its parameters.

Example 4.13: Unlocking KeyedServerLock
This servlet generates a KeyedServerLock license key for any given host and port number. It's passed the host and port via request parameters.

Example 4.14: Showing where the path leads
This servlet prints the extra path information it receives and the resulting translation to a real path. It's disabled to keep secret the ISP server's directory structure.
    • Try it (disabled for security)
    • Source

Example 4.16: Dynamically returning static files
This servlet serves files by using the getPathTranslated() and getMimeType() methods to return whatever file is given by the extra path information. It's disabled because the servlet would happily serve any files from this site.
    • Try it (disabled for security)
    • Source

Example 4.18: Serving an abstract resource, safely
This servlet views files only within its own context. Any files outside its context are inaccessible from the getServletContext().getResource() method. This servlet protects against access of files under WEB-INF and .jsp source using the ServletUtils.getResource() method from com.oreilly.servlet.

Example 4.19: Snooping headers
This servlet prints information about its HTTP request headers.

Example 4.21: Handling a file upload
This servlet can receive a multipart/form-data POST commonly used to upload files. It uses the com.oreilly.servlet.MultipartRequest utility class to manage the details of RFC 1867 parsing. The servlet is disabled due to space restrictions.


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

Copyright © 1999-2005 Jason Hunter
Privacy Policy
Last updated: March 1, 2009