You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christian Grobmeier <gr...@gmail.com> on 2011/11/13 17:35:02 UTC

utf8 problems...

Hi guys,

I am searching for a utf-8 problem in my app. I have struts 2 with
sitemesh 2.x bundled. backoffice is apache cayenne which connects to
mysql with:
&useUnicode=true&characterEncoding=utf8

Now I suspect sitemesh somehow. Any ideas were I could look appreciated

Is sitemesh still recommended btw? 2.x version is pretty old and 3.x
is in alpha for quite a while.

Cheers
Christian

-- 
http://www.grobmeier.de

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: utf8 problems...

Posted by Jeff Black <je...@yahoo.com>.
FWIW -- I know Matt Raible's AppFuse [1] uses Spring's CharacterEncodingFilter.

The blog-post [3] is just lagniappe.


Best,

jb

[1] http://appfuse.org/display/APF/Web+Filters

[2] http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/filter/CharacterEncodingFilter.html

[3] http://ibnaziz.wordpress.com/2008/06/10/spring-utf-8-conversion-using-characterencodingfilter/



________________________________
From: Maurizio Cucchiara <mc...@apache.org>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Monday, November 14, 2011 4:56 AM
Subject: Re: utf8 problems...

Christian,
this is the filter I was talking about:

public class CharacterEncodingFilter implements Filter {
    private String encoding;

    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws ServletException, IOException {
        resp.setCharacterEncoding(encoding);
        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {
        encoding=config.getInitParameter("encoding");
    }

}
-----------------------------------------------------------------------------------------------------------------------------------
web.xml

   <filter>
         <filter-name>CharacterEncoding</filter-name>

<filter-class>com.dbi.norma.filter.CharacterEncodingFilter</filter-class>
         <init-param>
             <param-name>encoding</param-name>
             <param-value>UTF-8</param-value>
         </init-param>
     </filter>

    <filter-mapping>
        <filter-name>CharacterEncoding</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>

-----------------------------------------------------------------------------------------------------------------------------------
Furthermore IIRC struts2 usually takes into consideration the jsp page
directive, particolarly the contentType attribute:

<%@ page contentType="text/html; UTF-8" %>

OTH


Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara


On 13 November 2011 18:31, Maurizio Cucchiara <mc...@apache.org> wrote:

> Hi Christian,
> I have been using SM in production environments for a long time now.
> AFAIK 3.x is fairly stable though is still alpha.
> The encoding issues are my nightmare  :), you don't never know where
> they come from.
> The default encoding of S2 is UTF8, anyway to enforce the concept you
> could always do:
>
> <constant name="struts.i18n.encoding" value="UTF-8"/> (struts.xml)
>
> <parser content-type="text/html;charset=UTF-8"
> class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
> (sitemesh.xml)
>
> I usually start from a very simple example, then go ahead (does your
> data display correctly without SM?).
> How did you import your data inside mysql?
>
> Ensure that your data was encoded correctly inside the DB itself:
> select hex(field) from Table where condition;
> As last option you can even consider a Character Encoding Servlet
> Filter, but to be frank I never felt the need to use it.
>
> Twitter     :http://www.twitter.com/m_cucchiara
> G+          :https://plus.google.com/107903711540963855921
> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
>
> Maurizio Cucchiara
>
>
>
> On 13 November 2011 17:35, Christian Grobmeier <gr...@gmail.com>
> wrote:
> > Hi guys,
> >
> > I am searching for a utf-8 problem in my app. I have struts 2 with
> > sitemesh 2.x bundled. backoffice is apache cayenne which connects to
> > mysql with:
> > &useUnicode=true&characterEncoding=utf8
> >
> > Now I suspect sitemesh somehow. Any ideas were I could look appreciated
> >
> > Is sitemesh still recommended btw? 2.x version is pretty old and 3.x
> > is in alpha for quite a while.
> >
> > Cheers
> > Christian
> >
> > --
> > http://www.grobmeier.de
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

Re: utf8 problems...

Posted by Maurizio Cucchiara <mc...@apache.org>.
Christian,
this is the filter I was talking about:

public class CharacterEncodingFilter implements Filter {
    private String encoding;

    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws ServletException, IOException {
        resp.setCharacterEncoding(encoding);
        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {
        encoding=config.getInitParameter("encoding");
    }

}
-----------------------------------------------------------------------------------------------------------------------------------
web.xml

   <filter>
         <filter-name>CharacterEncoding</filter-name>

 <filter-class>com.dbi.norma.filter.CharacterEncodingFilter</filter-class>
         <init-param>
             <param-name>encoding</param-name>
             <param-value>UTF-8</param-value>
         </init-param>
     </filter>

    <filter-mapping>
        <filter-name>CharacterEncoding</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>

-----------------------------------------------------------------------------------------------------------------------------------
Furthermore IIRC struts2 usually takes into consideration the jsp page
directive, particolarly the contentType attribute:

<%@ page contentType="text/html; UTF-8" %>

OTH


Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara


On 13 November 2011 18:31, Maurizio Cucchiara <mc...@apache.org> wrote:

> Hi Christian,
> I have been using SM in production environments for a long time now.
> AFAIK 3.x is fairly stable though is still alpha.
> The encoding issues are my nightmare  :), you don't never know where
> they come from.
> The default encoding of S2 is UTF8, anyway to enforce the concept you
> could always do:
>
> <constant name="struts.i18n.encoding" value="UTF-8"/> (struts.xml)
>
> <parser content-type="text/html;charset=UTF-8"
> class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
> (sitemesh.xml)
>
> I usually start from a very simple example, then go ahead (does your
> data display correctly without SM?).
> How did you import your data inside mysql?
>
> Ensure that your data was encoded correctly inside the DB itself:
> select hex(field) from Table where condition;
> As last option you can even consider a Character Encoding Servlet
> Filter, but to be frank I never felt the need to use it.
>
> Twitter     :http://www.twitter.com/m_cucchiara
> G+          :https://plus.google.com/107903711540963855921
> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
>
> Maurizio Cucchiara
>
>
>
> On 13 November 2011 17:35, Christian Grobmeier <gr...@gmail.com>
> wrote:
> > Hi guys,
> >
> > I am searching for a utf-8 problem in my app. I have struts 2 with
> > sitemesh 2.x bundled. backoffice is apache cayenne which connects to
> > mysql with:
> > &useUnicode=true&characterEncoding=utf8
> >
> > Now I suspect sitemesh somehow. Any ideas were I could look appreciated
> >
> > Is sitemesh still recommended btw? 2.x version is pretty old and 3.x
> > is in alpha for quite a while.
> >
> > Cheers
> > Christian
> >
> > --
> > http://www.grobmeier.de
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

Re: utf8 problems...

Posted by Christian Grobmeier <gr...@gmail.com>.
Maurizio,

thanks for your suggestion. With your mail I have found the solution.

On Sun, Nov 13, 2011 at 6:31 PM, Maurizio Cucchiara
<mc...@apache.org> wrote:
> <constant name="struts.i18n.encoding" value="UTF-8"/> (struts.xml)

had not effect - it seem it was enabled already

> <parser content-type="text/html;charset=UTF-8"
> class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
> (sitemesh.xml)

This killed everything - layout gone :-) I needed to remove the
charset you put into content type (and used an attribute called
"encoding"). But didn't help

But then I thought about this:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

This was only in my decorator jsp page. But sitemesh expects this to
be in every jsp page. I fixed it on some pages already and it seem to
help.

Cheers
Christian


> I usually start from a very simple example, then go ahead (does your
> data display correctly without SM?).
> How did you import your data inside mysql?
>
> Ensure that your data was encoded correctly inside the DB itself:
> select hex(field) from Table where condition;
> As last option you can even consider a Character Encoding Servlet
> Filter, but to be frank I never felt the need to use it.
>
> Twitter     :http://www.twitter.com/m_cucchiara
> G+          :https://plus.google.com/107903711540963855921
> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
>
> Maurizio Cucchiara
>
>
>
> On 13 November 2011 17:35, Christian Grobmeier <gr...@gmail.com> wrote:
>> Hi guys,
>>
>> I am searching for a utf-8 problem in my app. I have struts 2 with
>> sitemesh 2.x bundled. backoffice is apache cayenne which connects to
>> mysql with:
>> &useUnicode=true&characterEncoding=utf8
>>
>> Now I suspect sitemesh somehow. Any ideas were I could look appreciated
>>
>> Is sitemesh still recommended btw? 2.x version is pretty old and 3.x
>> is in alpha for quite a while.
>>
>> Cheers
>> Christian
>>
>> --
>> http://www.grobmeier.de
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
http://www.grobmeier.de

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: utf8 problems...

Posted by Maurizio Cucchiara <mc...@apache.org>.
Hi Christian,
I have been using SM in production environments for a long time now.
AFAIK 3.x is fairly stable though is still alpha.
The encoding issues are my nightmare  :), you don't never know where
they come from.
The default encoding of S2 is UTF8, anyway to enforce the concept you
could always do:

<constant name="struts.i18n.encoding" value="UTF-8"/> (struts.xml)

<parser content-type="text/html;charset=UTF-8"
class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
(sitemesh.xml)

I usually start from a very simple example, then go ahead (does your
data display correctly without SM?).
How did you import your data inside mysql?

Ensure that your data was encoded correctly inside the DB itself:
select hex(field) from Table where condition;
As last option you can even consider a Character Encoding Servlet
Filter, but to be frank I never felt the need to use it.

Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara



On 13 November 2011 17:35, Christian Grobmeier <gr...@gmail.com> wrote:
> Hi guys,
>
> I am searching for a utf-8 problem in my app. I have struts 2 with
> sitemesh 2.x bundled. backoffice is apache cayenne which connects to
> mysql with:
> &useUnicode=true&characterEncoding=utf8
>
> Now I suspect sitemesh somehow. Any ideas were I could look appreciated
>
> Is sitemesh still recommended btw? 2.x version is pretty old and 3.x
> is in alpha for quite a while.
>
> Cheers
> Christian
>
> --
> http://www.grobmeier.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org