Application Server Solutions for Microsoft IIS and ASP.NET
       solutions   products   partners   company   support   downloads         store
ServletExec Self-Help: FAQ
Back to Search >  Back to Search Results

Faq ID 128
Product ServletExec
Category Internationalization
Question When I call request.getParameter() I always get a String whose character encoding is ISO-Latin-1. But that is not the correct encoding for the parameters. What can I do?
Answer Here is a high level explanation of what is happening: ServletExec receives each request parameter as an array of raw bytes. Because there is no way for ServletExec to know what character encoding was used for the request parameters (a META tag will not do the trick), it converts each byte array into a Java String (16 bit Unicode) using "ISO8859_1" as the character encoding.
  • If you are using the ServletExec 5.x September 2007 hotfix (or a newer version of ServletExec such as SE 6.0) then you have 2 options:
    1. Use the setCharacterEncoding() method of the ServletRequest interface (introduced in the Servlet 2.3 Specification).
      See that specification and the Servlet 2.3 Javadocs for information regarding correct usage of that method.
    2. -OR-
    3. Pass a System property to the JVM at JVM startup time. For example to change the default request encoding from 8859_1 to UTF-8:
      -Dcom.newatlanta.servletexec.request.url.encoding=UTF-8
      Then calls to request.getParameter() will return UTF-8 encoded Strings. NOTE that *both* the parameter names & parameter values will have the same encoding so in the above example, the String you pass to getParameter() must be encoded using UTF8. NOTE: This feature is tracked via bug #2792
  • If you are using ServletExec 4.x you should use the setCharacterEncoding() method of the ServletRequest interface (introduced in the Servlet 2.3 Specification).
    See that specification and the Servlet 2.3 Javadocs for information regarding correct usage of that method.
  • If you are running ServletExec 3.1 or older then here are some possible workarounds:
    1. Edit servers.properties so that it includes the line:
      servletexec.request.params.charset=<character-encoding>
      For example:
      servletexec.request.params.charset=UTF8
      Then whenever you call request.getParameter() you'll receive a String whose character encoding is UTF8 instead of the default Latin-1.
    2. After calling request.getParameter(), thus obtaining a String whose character encoding is Latin-1, re-encode the String by:
      • converting it back into a byte array with:
        byte[] bytes = parameterValue.getBytes("ISO8859_1");
      • creating a new String object from the byte array using whatever character encoding you need:
        paramValue = new String(bytes, "<character-encoding>");

      If you are using ServletExec 4.0 or newer you should not use the SE 3.1 workaround mentioned directly above.
      Although it may actually work, using it with SE 4.x or newer is not recommended.


If this FAQ does not solve your issue, then you may very well benefit from reading SE FAQ #360
Readers of this FAQ may also benefit from reading SE FAQ #116



   
company media information terms of use privacy policy contact us