 |
: Product by OOP-Research |
 |
: Documentation written by OOP-Research |
 |
: Patch for the other vendor's system |
First example of FormGenerator API
This is the first-step example of OOP FormGenerator API.
This source code example consists of 2 Servlet:
- example.formgen1.Cgi
- example.formgen1.Verify
The first one generates the empty CGI FORM.
[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.
[CGI FORM with invalid input]
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.
In this source code example, all the response from Java Servlet (web application GUI, or View part of MVC (Model View Controller)) can be generated from the normal HTML (or any mark up language such as XHTML, WML and HDML).
Unlike the JSP/JSTL based solution (such as Apache Struts or JavaServer Faces), all the response can be written in just the HTML tags.
The web designers (or page authors) need not learn even a bit of custom tag libraries in JSP/JSTL.
Once the HTML is prepared, the Java Swing GUI based conversion tool generates the XML.
While in the conversion, you will be asked to specify the acceptable data type for each request parameter from the CGI FORM.
Given this XML, a few lines of codes will be enough for the input validation in your Servlet.
Second example of FormGenerator API
This is the second example of OOP FormGenerator 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 FormGenerator 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.
In this example, we add the additional text input to the CGI FORM of the first example.
The new text field in this example asks the user to enter the telephone number.
The expected pattern of the telephone number differs with the countries.
In U.S., the telephone number is something like 123-456-7890:
[Input validation for U.S.]
But it should be 12-34-56-78-90 in France:
[Input validation for 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, FormGenerator API makes the things very easy.
Free source code examples of file upload Servlet/JSP by multipart/form-data
These examples will show you how to upload the files by Servlet / JSP through multipart/form-data.
They depend on OOP MimeParser, the Java API for file upload Servlet/JSP.
This API parses the InputStream of multipart/form-data and saves the uploaded files under the specified directory.
With this Java API, you can:
- Restrict the size of the file to be uploaded
- Restrict the mime-types (Content-Type) of the file to be uploaded
- Restrict the width/height of the image file (JPEG, GIF or PNG)
- Specify where to save the uploaded file
If the user tries to upload the larger files or the files of the invalid mime-types, this API throws the exception. In this case, your Servlet/JSP can catch the exception and show the appropriate message. Your Servlets/JSP has the full control over where to save the uploaded files.
With the easy programming interface of this API, a few lines of code will be enough for your file upload Servlet/JSP. Please download these source code examples and try them.
How to send e-mail from Servlet / JSP with JavaMail API. You can upload files by multipart/form-data and attache them to the e-mail. You can send e-mails at the scheduled time.
When you specify when the e-mail will be sent, the available TimeZones will be listed and you can select the favorite Time Zone among them.
The e-mail is stored into the SQL table by the Object Serialization.
Once the e-mail is queued, the back-ground Thread will select it at the scheduled time and send it.
|