Hi, Jason.
Before I had tried to use request.setCharacterEncoding("UTF�8") in a JSP (independent
from Struts) and that did not work.
Now I tried using a filter, as you suggest, and it works like a charm. No more need to
patch RequestUtils, and I can also monitor and write warnings if the response's
character encoding is not UTF-8. It works both in Tomcat 4.1.30 and Tomcat 5.0.28.
I confess this approach is more elegant than the one I had in mind. Thank you for
sharing.
Hiran
-----------------------------------------
Hiran Chaudhuri
SAG Systemhaus GmbH
Elsenheimer Stra�e 11
80867 M�nchen
Phone +49-89-54 74 21 34
Fax +49-89-54 74 21 99
> -----Original Message-----
> From: Jason Lea [mailto:[EMAIL PROTECTED]
> Sent: Donnerstag, 7. Oktober 2004 10:31
> To: Struts Users Mailing List
> Subject: Re: Internationalizing a Struts project
>
> Yes, I use the setCharacterEncoding(...) in a filter on
> Tomcat 4.1.28 to handle UTF-8 encoded pages (mainly for
> communicating in Japanese, which should be a good a test as
> any for UTF-8). I set the encoding to UTF-8 on each page as
> Craig suggested so the browser knows the encoding, and use a
> Filter to force the requests to be UTF-8 encoded before
> struts reads the parameters.
>
> I don't know about other servlet containers. Perhaps those
> other containers are not complying to the specification.
>
> There used to be a good resource "*Struts i18n*
> <http://www.anassina.com/struts/i18n/i18n.html> by Aaron
> Rustad." which was at http://www.anassina.com/struts/i18n/i18n.html
>
> But it no longer appears to exist that showed some easy steps
> to make everything work nicely.
>
>
> [EMAIL PROTECTED] wrote:
>
> >Hi, Jason.
> >
> >Have you tried using setCharacterEncoding(...)? For me on
> Tomcat 4.1.30 it showed no result at all, and other solutions
> available on the web state that setCharacterEncoding should
> work but has problems on many servlet containers. Therefore
> all I found refers to creating new strings from getParameter()....
> >
> >Hiran
> >
> >-----------------------------------------
> >Hiran Chaudhuri
> >SAG Systemhaus GmbH
> >Elsenheimer Stra�e 11
> >80867 M�nchen
> >Phone +49-89-54 74 21 34
> >Fax +49-89-54 74 21 99
> >
> >
> >
> >
> >
> >
> >>-----Original Message-----
> >>From: Jason Lea [mailto:[EMAIL PROTECTED]
> >>Sent: Mittwoch, 6. Oktober 2004 22:01
> >>To: Struts Users Mailing List
> >>Subject: Re: Internationalizing a Struts project
> >>
> >>You should only need to do the following:
> >>
> >> request.setCharacterEncoding("UTF-8")
> >>
> >>before the form is populated. I think you can do this by
> >>overriding the RequestProcessor. I use a filter to do this instead.
> >>
> >>[EMAIL PROTECTED] wrote:
> >>
> >>
> >>
> >>>Hi, Craig.
> >>>
> >>>You hit the bull's eye. No I claim this not only to be a
> >>>
> >>>
> >>JSP/Servlet problem.
> >>
> >>
> >>>The way you describe will cause the browser to encode all
> >>>
> >>>
> >>form data with UTF-8.
> >>
> >>
> >>>Unfortunately the servlet container (Tomcat in my case) does
> >>>
> >>>
> >>not know about this.
> >>
> >>
> >>>To obtain the correct parameter values, someone has to call
> >>>
> >>>
> >>(beware of
> >>
> >>
> >>>Nullpointers and UnsupportedEncodingExceptions)
> >>>
> >>>new
> >>>
> >>>
> >>String(request.getParameter("...").getBytes("ISO-8859-1"), "UTF-8")
> >>
> >>
> >>>This conversion must be applied to all parameter values.
> >>>
> >>>
> >>Either it is done once in Struts, or each and every Action
> >>has to convert the values Struts provides, breaking this
> >>really nice architecture of FormBeans. In Cocoon I see this
> >>type of conversion can be turned on and off by configuration.
> >>
> >>
> >>>I recommend changing the RequestUtils' populate method
> >>>
> >>>
> >>(which I did for me), or enhancing the RequestProcessor to
> >>allow RequestUtils to be replaced by subclasses thereof so
> >>people like me can plug in their own RequestUtils. What do
> you think?
> >>
> >>
> >>>Hiran
> >>>
> >>>-----------------------------------------
> >>>Hiran Chaudhuri
> >>>SAG Systemhaus GmbH
> >>>Elsenheimer Stra�e 11
> >>>80867 M�nchen
> >>>Phone +49-89-54 74 21 34
> >>>Fax +49-89-54 74 21 99
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>>-----Original Message-----
> >>>>From: Craig McClanahan [mailto:[EMAIL PROTECTED]
> >>>>Sent: Dienstag, 5. Oktober 2004 23:47
> >>>>To: Struts Users Mailing List
> >>>>Subject: Re: Internationalizing a Struts project
> >>>>
> >>>>On Tue, 5 Oct 2004 16:31:14 +0200,
> >>>>[EMAIL PROTECTED]
> >>>>
> >>>>
> >><[EMAIL PROTECTED]> wrote:
> >>
> >>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>>Hi there.
> >>>>>
> >>>>>I'm working on i18n of a Struts based project. All
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>references I find about this topic deal with using messages
> >>>>
> >>>>
> >>depending
> >>
> >>
> >>>>on the user's locale. Has anyone ever experienced problems with
> >>>>national special characters (such as currency symbols for
> >>>>
> >>>>
> >>sterling or
> >>
> >>
> >>>>euro?
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>>Hiran
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>This issue is more related to the way JSP works than Struts, but
> >>>>here's a summary.
> >>>>
> >>>>The most important consideration for national characters is the
> >>>>character encoding that will be used to send the response
> >>>>
> >>>>
> >>back to the
> >>
> >>
> >>>>browser. Unless you ask for something different
> >>>>
> >>>>
> >>explicitly, JSP pages
> >>
> >>
> >>>>are always sent back in ISO-8859-1 (basically 7-bit ASCII),
> >>>>
> >>>>
> >>which will
> >>
> >>
> >>>>create problems with characters outside the 7-bit range.
> >>>>
> >>>>To ask for the content encoding to be set differently,
> you use the
> >>>>page directive at the top of your JSP pages, for example,
> to select
> >>>>UTF-8:
> >>>>
> >>>> <%@ page contentType="text/html;charset=UTF-8" %>
> >>>>
> >>>>If all of your national characters are produced by custom
> >>>>
> >>>>
> >>tags (such
> >>
> >>
> >>>>as <bean:write> or <html:input> in the case of Struts),
> >>>>
> >>>>
> >>this should be
> >>
> >>
> >>>>all you need. If you also want to use literal characters in the
> >>>>template text of your JSP page, you have to go one step
> further --
> >>>>actually store the source code of your JSP page in an appropriate
> >>>>encoding, and tell the JSP compiler what that encoding is. The
> >>>>details of how you save pages in a particular encoding will
> >>>>
> >>>>
> >>depend on
> >>
> >>
> >>>>the text editor or IDE you are using, but the mechanism
> to tell JSP
> >>>>about it is standard. So, if you also use UTF-8 encoding
> for your
> >>>>source page, you'd say:
> >>>>
> >>>> <%@ page pageEncoding="UTF-8"
> >>>>contentType="text/html;charset=UTF-8" T%>
> >>>>
> >>>>Craig McClanahan
> >>>>
> >>>>------------------------------------------------------------
> >>>>
> >>>>
> >>---------
> >>
> >>
> >>>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>>>For additional commands, e-mail: [EMAIL PROTECTED]
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>-----------------------------------------------------------
> ----------
> >>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>>For additional commands, e-mail: [EMAIL PROTECTED]
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>--
> >>Jason Lea
> >>
> >>
> >>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
>
>
> --
> Jason Lea
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]