Ben,
Thanks for asking this question - this is almost
exactly the question I posted yesterday. I didn't get
an answer ;-) but perhaps we can generate some interest
if we keep bringing it up.
The form bean user is out in the cold right now. Even
with setEncoding() in 2.3, it still has to be called
before the POST data is processed. By the time the
action servlet gains control, the conversion has happened.
I suggested (like you did) that perhaps the best
place to do this is as an "encoding" tag attribute in the form,
or the individual text tags, etc.
Right now, I rely on app-server specific features to
set the encoding of POST data on a per-web-application
basis. I wouldn't mind a similar mechanism in the struts-config
file. That would be much more portable than what I'm
doing now.
Scott
> -----Original Message-----
> From: Ben Flaumenhaft [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, July 05, 2001 4:40 PM
> To: '[EMAIL PROTECTED]'
> Subject: Encodings on form submits?
>
>
>
> 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
>