OOP-ResearchMake It Simpler by Object Oriented Programming

How to specify the charset by OOP MimeParser: Java API for file upload JSP/Servlet by multipart/form-data

Java API for file upload JSP/Servlet by multipart/form-data. This Java API makes your JSP/Servlet ready for 2 bytes characters (Japanese Shift_JIS, Chinese BIG5, Chinese GB2312 or Russian KOI8-R).
For i18n (Internationalization) of your Servlets/JSP, the text parameters in the CGI FORM must be decoded by the correct charset. For example, if the text parameter is encoded by Japanese Shift_JIS and sent as the HTTP request of multipart/form-data, your JSP/Servlet must decode it also by Japanese Shift_JIS. This page describes how to specify the charset by OOP MimeParser.

Related Pages:


By which charset to decode the text parameter

The text parameter includes:

  • INPUT with the type of TEXT
  • INPUT with the type of HIDDEN
  • INPUT with the type of PASSWORD
  • INPUT with the type of CHECKBOX
  • INPUT with the type of RADIO
  • INPUT with the type of SUBMIT
  • SELECT
  • TEXTAREA
To make your Servlet truly internationalization (i18n) ready, your Servlet needs to decode the text parameter by the charset same as it is encoded. For example, if the text parameters are encoded by Japanese Shift_JIS, these text parameters need to be decoded by Japanese Shif_JIS. This is also true for Chinese BIG5, Chinese GB2312 or Russian KOI8-R.
By MimePaser, you can specify the charset in various ways.

The default charset is specified in the property resource file. This default charset is used by the following 8 methods:
  • parseAndSave(HttpServletRequest req, String dir)
  • parseAndSave(HttpServletRequest req, String dir, int max)
  • parseAndSave(HttpServletRequest req, String dir, Set mime)
  • parseAndSave(HttpServletRequest req, String dir, int max, Set mime)
  • parseOnly(HttpServletRequest req)
  • parseOnly(HttpServletRequest req, int max)
  • parseOnly(HttpServletRequest req, Set mime)
  • parseOnly(HttpServletRequest req, int max, Set mime)
This default charset can be overridden within your Servlet/JSP by the second parameter of:
  • parseAndSave(HttpServletRequest req, String ch, String dir)
  • parseAndSave(HttpServletRequest req, String ch, String dir, int max)
  • parseAndSave(HttpServletRequest req, String ch, String dir, Set mime)
  • parseAndSave(HttpServletRequest req, String ch, String dir, int max, Set mime)
  • parseOnly(HttpServletRequest req, String ch)
  • parseOnly(HttpServletRequest req, String ch, int max)
  • parseOnly(HttpServletRequest req, String ch, Set max)
  • parseOnly(HttpServletRequest req, String ch, int max, Set mime)
But, the charset specified by these method can also be overriden. In case that TEXT INPUT, SELECTION or HIDDEN INPUT whose name is charset is found in the request, its value will be used. For example, the FORM below includes the HIDDEN INPUT whose name is charset. On the destination Servlet/JSP, MimeParser picks up the value of this HIDDEN INPUT and decodes the rest of the text parameters by Shift_JIS.
Form with charset


Moreover, if the charset header is set by the browser, it will take precedence all of them. This is because the charset sent from the browser is the most reliable. But the browsers in the real world does not set charset header.

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.