Hi,

This is a problem with all servlet engines and is not addressed in the
specification (at least not to help solving the problem in the Real World
(TM)).

Contrary to what you would expect an HTTP POST with FORM data does not
contain character encoding information (see the corresponding RFC's). If
your servlet receives FORM data in any non ISO-Latin-1 encoding namely UTF-8
or any Asian charset you have to post process your FORM data (i.e. keys AND
values) yourself e.g. with the following method.

But you have to know the correct expected encoding from the page containing
the FORM. All browser that I know of post FORM data with the charset of the
page containing the FORM. If you don't know the encoding then you can forget
about handling this situation ...

     /**
     * Decodes a value from a post request with a specific decoding charset.
     *
     * @param postData the data to decode
     * @param charset the charset to use for decoding
     *
     * @param The decoded value or the same value if the char set was
unknown
     */

    public static String decodePOSTData(String postData, String charset)
    {
        try
        {
            byte bytes[] = new byte[postData.length()];
            postData.getBytes(0, postData.length(), bytes, 0);
            return new String(bytes, charset);
        }
        catch (Exception exc)
        {
            return postData;
        }
    }


I encountered this while using Java Web Server and posting the Euro currency
symbol. As this is not part of ISO-Latin-1 I got strange errors. Maybe
someone from the specification team can shed an light on this.

Cheers
Christian
--
Christian Mallwitz INTERSHOP Communications Germany
Senior Software Engineer    phone: +49 3641 894 334

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to