Introduction To Tek271 Servlet Utilities

A Java open source library of Servlet utilities.

By Abdul Habra
Email ahabra@yahoo.com
URL www.tek271.com
Version  1.00
Date 2008.05.26

Downloads
This software is open source, free, and uses LGPL license.
tek271.servletUtilieties.2008.05.26.zip: Source, JAR, JavaDocs.
Java Docs.

1. Introduction
This is a simple library of servlet-related utilities. The following gives a high level summary of each class in the library:
  1. ServletIO: Methods to write messages and exception's stack trace to the response, dump a request to the response, and to read files from file system.
  2. ServletUtilities: Different utility methods, like forward, redirect, and accessing session attributes.
  3. RequestReader: Read request's data into a bean whose properties names should match the names of the request's parameters, taking care also of requests that contain uploaded files. This is a very handy class to read uploaded file.

The following examples show how to use the RequestReader class.

Example 1: Copy request's data to an existing bean

RequestReader rr= new RequestReader(request);
rr.copyToBean(myBean);   // myBean should have been instantiated before
// now myBean's properties or public fields contain the request's parameters.

Example 2: Copy request's data to a new bean

RequestReader rr= new RequestReader(request);
MyClass myBean= rr.toBean(MyClass.class);

Example 3: Read request's data that can include uploaded files

String uploadDir= "upload/dir/";
String fileNameSuffix= ".up";    // uploaded files will be named with .up suffix
RequestReader rr= new RequestReader(request, uploadDir, fileNameSuffix);
MyClass myBean= rr.toBean(MyClass.class);
if (rr.hasUploads()) {
  Map<String, String> uploads= rr.getUploadedFiles();
  for (String fileName: uploads.keySet() ) {
    // fileName is the name of the file as determined by the client
    String filePath= uploads.get(fileName);
    // filePath is the path and name to the file stored on the server
    // ... do something with the uploaded file
  }
}
2. Requirements
This library requires JRE 1.5 or higher. Additionally, the JAR files included with the download lib directory are also required.

Changes

Version 1.00, 2008.05.26
First public release

Comments



ċ
tek271.servletUtilieties.2008.05.26.zip
(3152k)
Abdul Habra,
Mar 28, 2011, 3:25 PM
Comments