Folks,

I'm struggling with how to handle form submissions with non-Latin character
encodings using a Struts action and form beans.

As I understand it, browsers use the character encoding of the form's page
(hex-encoded) for submitting form parameters. I've seen plenty of code to
convert request parameters by hand, e.g.

        try
        {
            return new String(inParam.getBytes("8859_1"), encoding);
        }
        catch (UnsupportedEncodingException e) 
        {
            return inParam;
        }

... but this implies that you know the character encoding. Until Servlet 2.3
is standard, you can't just say request.setEncoding ().

So: how to do this in Struts? Ultimately, what I need is my form beans to
have their Strings set properly.

I can think of a few ways.

(1) Let the form bean handle it on set () methods for Strings. Every form
class could extend a base class with a decodeString (), and every form class
could call this method.

I'm not thrilled about this, since it'd be easy to forget and it's a lot of
extra coding on every set call.

(2) Modify Struts to do this automatically. This isn't trivial, since the
calls to populate beans 
are buried pretty deeply in ActionServlet, RequestUtils, and BeanUtils. 

In either case, the handler (whether Struts utils or the beans themselves)
would need to know the encoding to use! The best I can come up with is that
every form would embed a hidden parameter "encoding" -- this is how iPlanet
handles this, they have a j_encoding parameter on forms which tells the
handler how to decode params. (I could modify html:form to do this
automatically, too ...)

Thoughts?

Thanks,
Ben

Reply via email to