Thanks Adam!
Read below for comments!
----- Original Message -----
From: "Adam Hardy" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Sunday, February 29, 2004 2:19 PM
Subject: Re: Problems with UTF-8 and forms
> On 02/28/2004 11:37 PM Jon Bohm wrote:
> > Hello,
> >
> > I'm using Aaron Rustads SetCharacterEncodingFilter-filter for Struts
> > but with mixed results (see link below).
> >
> > * All my Resource-, JSP- and Java-files are saved in UTF-8 format.
>
> Hi Jon,
> do you mean you have to use a UTF-8 editor to edit the files? This
> doesnt sound right. I have not done this yet for my app, but it's on the
> list to do: for your Resource files, for UTF-8, you should write them in
> UTF-8 and then convert them to ascii using native2ascii, a Java app that
> comes with the Java SDK.
>
> I think your JSPs and Java files should be uncoded for the character set.
Resource-, JSP- and Java-files are now 8859_1 encoded.
Characters inside resource files are converted to UTF-8 characters with the
native2ascii tool (files still encoded in 8859_1)
Swedish characters (even uppercase) works great!
Success so far!
>
> > First problem: Posted data from a web form is sent as UTF-8, which is
> > great - the filter works! But if I want to print the form bean
> > values in another JSP-page with the bean:write tag, the bean property
> > must return 'new String(oldString.getBytes(), "UTF-8")' for it to
> > work. Am I doing something wrong here?`
>
> Probably related to the issue above. That conversion shouldn't be
> necessary when using the filter.
>
>From the post I get the UTF-8 encoded value (through filter) and store it in
a session bean.
public ActionForward execute( ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response )
throws Exception
{
MyFormBean formBean = (MyFormBean) form;
CustomBean bean = new CustomBean();
bean.setValue( formBean.getValue() );
request.getSession().setAttribute("mybean", bean);
}
Then when I print the value in the JSP-page I get distorted characters.
<bean:write name="mybean" property="value" scope="session"/>
BUT if I rewrite my custombean's getValue method it all works fine (except
for swedish uppercase letters):
public String getValue()
{
return new String( value.getBytes(), "UTF-8");
}
>
> > Second problem: Swedish letters Ä Ö and Å are not
> > compatible with UTF-8? These characters A (with two dots), A (with a
> > circle) and O (with two dots) never work, which is the opposite from
> > their lowercase counterparts which works fine.
So the problem still remains. This should be easy right?
>
> You don't mention what version of tomcat you are using. It is also
> affected by JSTL if you use that. A good debugging help is to put
> something like this at the end of your JSP:
Apache Tomcat/5.0.12
Java 1.4.2_01-b06
Struts 1.1 (I think - how do I check?)
Windows XP (I know, I'm a Linuxdude gone bad)
>
> out.print("<div>locale: " +
> session.getAttribute(org.apache.struts.Globals.LOCALE_KEY) +
> "</div>");
> out.print("<div>request character encoding=" +
> request.getCharacterEncoding() + "</div>");
> out.print("<div>response character encoding=" +
> response.getCharacterEncoding() + "</div>");
>
>
> > http://www.anassina.com/struts/i18n/i18n.html
>
> Good link, but getting a little out-of-date now.
You have a better one? :)
>
>
> Adam
- Jon
> --
> struts 1.1 + tomcat 5.0.16 + java 1.4.2
> Linux 2.4.20 Debian
>
>
> ---------------------------------------------------------------------
> 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]