Servlets.com

Home

What's New?

com.oreilly.servlet

Servlet Polls

Mailing Lists

List Archives

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 4 Examples from Java Servlet Programming

  • 4-2: Getting init parameter names
  • 4-3: Snooping the server
  • 4-4: A servlet locked to a server
  • 4-5: Can they be trusted?
  • 4-6: Hey, I remember you!
  • 4-7: Snooping parameters
  • 4-8: Unlocking KeyedServerLock
  • 4-9: Showing where the path leads
  • 4-10: Dynamically returning static files
  • 4-14: Snooping headers
  • 4-16: Reading parameters passed by POST
  • 4-17: 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.4: 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.5: Can they be trusted?
This servlet checks the client machine and only allows access if the client appears to be coming from inside the United States or Canada. A servlet like this could help restrict the export of strong encryption.

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

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

Example 4.8: 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.9: 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.10: 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.14: Snooping headers
This servlet prints information about its HTTP request headers.

Example 4.16: Reading parameters passed by POST
This HTML page and servlet demonstrate how a servlet can handle a POST requests containing form data.

Example 4.17: 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   Archives
Engines   ISPs   Tools   Docs   Articles   Soapbox   Book

Copyright © 1999-2005 Jason Hunter
Privacy Policy

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