OOP-ResearchMake It Simpler by Object Oriented Programming

OOP RequestParser API: HTTP request parameters in the URL-encoded form or in the byte arrays

This Java API parses the HTTP request parameters in the effective way. It also implements the methods to access the URL-encoded request parameters, or the request parameters in the byte array.
To get the better performance, this API postpones the conversions among the URL-encoded parameters, the byte arrays and decoded String until they are really required. By this strategy, Servlet can get the HTTP request parameters in the various forms.

NOTE:

This API is capable only for the HTTP request with application/x-www-form-urlencoded. To accept the HTTP request with multipart/form-data, please use OOP MimeParser API.

Related Pages:


Do you really need the decoded parameters ?

When your JSP/Servlet receives a set of the HTTP request parameters, it is common to call:

  • HttpServletRequest.getParameters(String name)

(or its variants) for your JSP/Servlet to get their values.
Because the HTTP request parameters are sent in the form of URL-encoded String, the above method includes the repeated conversion between the String and byte arrays behind the scene. But, as you know, the JSP/Servlet specification (at least, up to Version 2.4) does not define the methods to get the request parameters in the intermediate stage. Becasue only the request parameters in the form of the decoded String (that is the original String) are human readable, we tend to think that we always need them. But, in fact, it is not always true. There are the cases that the URL-encoded String or the byte arrays are enough.
This Java API implements the methods for getting the request parameters in any stage. For instance,



   // Get the instance of RequestParser.
   RequestParser reqParser=RequestParser.getInstance();

   // Parse the HTTP request only in the very first stage
   // and create ParsedRequestParameters object.
   ParsedRequestParameters params=reqParser.parseSimple(req);

   // Get the request parameter value for "param1", in the
   // form of URL-encoded String.
   // At this point, all parameters are left in the form of
   // URL-encoded String.
   String encoded=params.getEncodedString("param1")

   // Get the request parameter value for "param2", in the
   // form of byte arrays.
   // At this point, only this parameter is converted to the
   // byte arrays.
   // The rest of parameters are still left in the form of
   // URL-encoded String.
   byte[] byte=params.getDecodedBytes("param2")

   // Get the request parameter value for "param3", in the
   // form of the decoded String (that is the original String).
   // At first, this method converts the specified parameter
   // to the byte arrays.
   // Then, it converts the byte arrays to the decoded String.
   // The rest of parameters are left unchanged.
   String decoded1=params.getDecodedString("param3");

   // Now, let's play with "param2" again.
   // Get it in the form of the decoded String.
   // Because the specified parameter is already converted to
   // the byte arrays (see above), this method only converts
   // those byte arrays to the decoded String, and that all.
   // The rest of parameters are left unchanged.
   String decoded2=params.getDecodedString("param2");


Note that each method triggers only the conversions that are required at that point. And the converted parameters are kept in the cache to avoid the repeated conversions.

Go Site Map

Download

This API is now a part of Bento framework. There are the better documentations and source code examples on the web site for Bento framework. There, you will also find the link to download the entire framework or each API in it.

Caution!
All the APIs for Servlet/JSP introduced by this web site are now included in Bento framework:
  • Simpler than JSTL or Apache Struts
  • MVC framework by HTML
  • Input validation from CGI FORM
  • Easy user authentication
  • Easy localization (L10n)
To download the APIs and source code examples, please visit the web site of Bento framework.


JBuilder 2007


General Information

For Java Development

Java and all Java-based trademarks and logos are trademarks or registered of Sun Microsystems, Inc. in the United States and other countries.


ALL CONTENTS COPYRIGHT 1997-2007, OOP-Research Corporation. All rights reserved.