OOP-ResearchMake It Simpler by Object Oriented Programming

i18n, Apache Tomcat, Servlets, JSP, Shift_JIS, BIG5, GB2312, KOI8

The i18n patch for Apache Tomcat. JSP or Servlets on Apache Tomcat can accept HTTP POST request with 2 bytes characters, such as Japanese Shift_JIS, Chinese BIG5, Chinese GB2312 or Russian KOI8-R. When the original parameter string in POST data contains the 2 byte characters, Tomcat may have some difficulty in decoding the encoded POST parameter. This patch fixes this problem.


This patch does not work on Tomcat 3.2 and later. Instead, please try OOP MimeParser, that will run on any Servlet container.

1: What is Tomcat

As you know, JSP and Servlet plays the role of the user interface of J2EE applications. I'm sure that the serious system developers in the world are desire for the cool servlet server. And now, Tomcat is available.
Tomcat3.1 is the implementation of JavaServerPages1.1 and Servlet2.2 specification and developed and maintained by the Jakarta Project.

Go Site Map

2: My solution (Un-official patches)

But at this time, there are some restrictions:

  • The mapping of the path and the context defined on the JServ module side is not reflected to the Tomcat servlet server. For example, if you map the path of /test to the context of /examples, the request such as http://foo.com/test/myservlet should be redirected to Tomcat as the request to the servlet of 'myservlet' in the context of '/examples'. But Tomcat tries to find the servlet of 'myservlet' in the contest of '/mytest', not the mapped context of '/example' and failed to invoke it.
  • The JServ module cannot obtain the configuration information of the Tomcat servlet server. The request of http://foo.com/jserv/ returns the page reporting the configuration of the JServ module, but the configuration of Tomcat cannot be reported.
  • The corrupted parameter string is returned by Request.getParameter(String name), when the original character sequence contains the 2 bytes characters, such as Japanese character.
Solutions to these have been discussed in the Tomcat developer mailing list, so some of them will be un-locked at the next version of Tomcat. (As for the internationalization of the parameter string, we have some difficulties to manage within the current Servlet Specification version 2.2. For details, please read 'My proposal to Servlet and JSP Specification.)
But for your convenience, I modified and appended some classes and uploaded their source. They are:
  • Modified class
    1. org.apache.tomcat.core.ContextManager
    2. org.apache.tomcat.core.RequestImpl
    3. org.apache.tomcat.core.Request
    4. org.apache.tomcat.core.RequestInterceptor
    5. org.apache.tomcat.core.BaseInterceptor
    6. org.apache.tomcat.service.connector.Ajp12ConnectionHandler
  • Appended class
    1. com.oopreserch.tomcat.request.FixCharset
    2. com.oopreserch.tomcat.util.CharsetToJavaEnc
    3. com.oopreserch.tomcat.servlets.StatusServlet
NOTE:
Of course, I've posted these sources to the Tomcat developer mailing list. But they are not necessarily adopted as they are, and the next version of Tomcat will include more optimized class based on the farther discussion of the mailing list. In this point, the classes above are UN-OFFICIAL ones.

You can download my source distribution here.

Go Site Map

This patch does not work on Tomcat 3.2 and later. Instead, please try OOP MimeParser, that will run on any Servlet container.

3: Compiling the modified classes and helper classes

Download my distribution and extract it. When extracted, the directory 'tomcat_oop_patch' is created. Please confirm that 'CLASSPATH' and 'TOMCAT_HOME' environment variables are set properly. Change to the directory of 'tomcat_oop_patch' and execute the shell script named 'build_oop.sh'. This script compiles the updated class and my helper class, and then updates the '$TOMCAT_HOME/lib/webserver.jar' file.

Go Site Map

4: Configuration

In $TOMCAT_HOME/conf/server.xml, com.oopreserch.tomcat.request.FixCharset must be specified as one the the RequestInterceptor. To decode parameter string properly, this helper class adapts the 'option A' of My Proposal to Servlet and JSP Specification, so you need to supply the charset in which the parameter string is encoded. It looks like this:

<RequestInterceptor
    className="com.oopreserch.tomcat.request.FixCharset"
    Charset="Shift_JIS" />


Go Site Map

In addition, when you'd like enable com.oopreserch.tomcat.servlets.StatusServlet, you need to register it in $TOMCAT_HOME/conf/web.xml with the appropriate 'url-pattern'.
To handle the request from the 'jserv-status' function of the JServ module, the servlet server must hold the servlet which can be invoked by the 'url-pattern' of '/org.apache.jserv.JServ'. As for each context, the mapping of the 'url-pattern' and the servlet can be defined in 'WEB-INF/web.xml' which resides in the document base corresponding to the requested context. In case of this request, such a servlet must be stored in the context of "", which can be configured by

This file must contains the following elements:

  • In the <servlet> element,
            <servlet-name>
                status
            </servlet-name>
            <servlet-class>
    	    org.apache.tomcat.servlets.StatusServlet
            </servlet-class>
    
  • and in <servlet-mapping> element,
            <servlet-name>
                status
            </servlet-name>
            <url-pattern>
                /org.apache.jserv.JServ
            </url-pattern>
    
You may wonder where 'org.apache.tomcat.servlets.StatusServlet' class file is stored. It is already stored $TOMCAT_HOME/lib/webserver.jar by running 'build_oop.sh'. With this configuration, we can see the configuration both of JServ and Tomcat by the request of
  • http://www.foo.com/jserv/


Go Site Map

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.