Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

Why admin webapp does not support umlauts

Eckard Buchner

2004-01-20


the tomcat admin webapp does not support umlauts (german äöü, french éâ
etc). I did some debugging through tomcat and struts code:

* the JSP pages contain a UTF-8 page header
<%@(protected)" %>

* the browser then sends form input as "utf-8" to the web server

* struts does not know about the page encoding and transforms the bytes
from the browser into standard format,
umlauts are lost

* I added some test code, that converts the request parameter input to
UTF-8

org.apache.struts.util.RequestUtils

  public static void populate(Object bean, String prefix, String suffix,
                    HttpServletRequest request)
    ....
   properties.put(stripped,
readUtf8(request.getParameterValues(name)));
    ...
      }

  private static Object readUtf8(String[] strings) throws
ServletException {
   String out[] = new String[strings.length];
   for (int i = 0; i < strings.length; i++) {
    try {
      out[i] = new String(strings[i].getBytes(), "utf-8");
    } catch (UnsupportedEncodingException e) {
      throw new ServletException("BeanUtils.populate", e);
    }
   }

   return out;
  }


* seems to work. Umlauts are handled correctly, but of course this is not
a solution

How could the application bean (e.g. org.apache.webapp.admin.users.UserForm) handle the UTF-8 encoded form input? Or maybe there is a way to
configure struts to handle UTF-8 input correctly?

The problem appears in Tomcat 4.1.x and 5.x

Regards
Eckard
©2008 junlu.com - Jax Systems, LLC, U.S.A.