Java API and examples by XML : Simpler than JSP/JSTL, Apache Struts or JavaServer Faces : Input validation from CGI FORM : Localization (L10n) : Servlet in Japanese Shift_JIS, Chinese BIG5 or GB2312
Java API and examples by XML. Simpler than JSP/JSTL, Apache Struts or JavaServer Faces. Input validation from CGI FORM. Localization (L10n). Servlet in Japanese Shift_JIS, Chinese BIG5 or GB2312.
In the template framework design by OOP ViewGenerator API, all the response can be generated from the normal HTML (or any other mark-up languages such as XHTML, WML or HDML).
Unlike the JSP/JSTL based-solutions (such as Apache Struts and JavaServer Faces), the web designers (or page authors) need not learn a bit of custom tag libraries.
They can write the view part of the web applications in the normal HTML, by their favorite ways.
Once you finish the conversion, please place the generated XML into:
directory (or its sub-directories).
Then, ViewGenerator API in your Servlet will read it.
Your Servlet can insert the arbitrary Strings into the HTML fragments and send the concatenated HTML tags to the web browser.
Because the XML includes the acceptable data types from the CGI FORM, a few lines of code are enough for the input validation in your Servlet.
First example of ViewGenerator API
This is the first-step example of OOP ViewGenerator API. This source code example consists of 2 Servlet:
The first one generates the empty CGI FORM.
The POST request from this CGI FORM will be sent to the second Servlet. The second Servlet verifies all the request parameters. If some request parameter is invalid, the second Servlet shows the same CGI FORM again. But, at this time, the CGI FORM includes the previous request parameters in it, as the default values. In addition, this CGI FORM indicates which input is invalid.
The POST request from this CGI FORM will be sent to this Servlet again.
When all the request parameters are verified, the second Servlet shows the HTML table including them.
Second example of ViewGenerator API
This is the second example of OOP ViewGenerator API.
In case of the JSP/JSTL based solution like Apache Struts or JavaServer Faces, the localized message should be written in the property resource file for the expected Locale.
In the framework design by OOP ViewGenerator API, Localization (L10n) of Servlet can be very easy.
For each expected Locale (language preference), the localized messages can be written in the normal HTML.
So, there is not difficulty even in the 2 bytes characters such as Japanese Shift_JIS, Chinese BIG5 or GB2312.
But it should be 12-34-56-78-90 in France:
This means the different algorithm must be applied to the input validation for each Locale. It may sound somewhat difficult. But, don't worry! Because the acceptable data type can also be written in the XML, ViewGenerator API makes the things very easy.
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.
Apache Tomcat behind the Apache web server (HTTP daemon) can accept the HTTP request for more than one host. With this Java API, Servlet can take the advantage of this feature.
For some set of initialization parameters, the different values should be set for each host, when the single instance of Tomcat accepts the HTTP requests to multiple hosts.
But, as for another set of initialization parameters, you may want to set the same value for all the hosts.
By this API, both of these types of initialization parameters can be defined in the single XML.
In addition to the typical types of values, such as int or String, the XML can define the Set and arrays of them.
And this API implements the methods to get the initialization parameters in the Set or arrays.
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.