UTF-8 woes

253 views
Skip to first unread message

cjn

unread,
Sep 6, 2011, 4:34:03 PM9/6/11
to SiteMesh 2 Users, ch...@nappin.com
Hi All,

I'm using SiteMesh 2.4.2 with Spring WebFlow on WebLogic 10.3.2 with
Java 6, and am really struggling to get Unicode characters to display
properly. If I disable the sitemesh filter then the characters are
displayed ok, so the issue appears to be specific to SiteMesh.

After googling at length and reading through the sitemesh docs, I've
followed these steps:
- all JSPs (original pages and decorator) use UTF-8 encoding and
content type of "text/html; charset=UTF-8"

- added the Spring CharacterEncodingFilter (encoding = UTF-8,
forceEncoding = true) before which calls response.setEncoding(..) -
and I've also tried my own filter which calls
response.setContentType("text/html; charset=UTF-8") too

- set an explicit contentType for my Spring View Resolver (again "text/
html; charset=UTF-8") - not sure this step actually made a difference

However any non-standard characters (e.g. certain welsh characters) in
my pages, when decorated by SiteMeshl, get mangled.

I can see lots of folks have previously hit this, without success. I'm
also not sure how active this group is. Any help gratefully received!

Cheers,

cjn

cjn

unread,
Sep 7, 2011, 6:06:59 PM9/7/11
to SiteMesh 2 Users
Right, I've finally cracked it. Since this seemed (at least to me)
pretty non-obvious I'll post my solution here in the hope that others
might get to see it and it might help one or two other folks...

The issue was the filter not being applied, and that I had to use my
own custom filter to set the content type and encoding via
response.setContentType("text/html; charset=UTF-8") - since the Spring
CharacterEncodingFilter didn't appear to be sufficient for SiteMesh.

As is usual practice these days, in my web app I have browser URLs
like /flow/* mapped to Spring WebFlow (via the Spring dispatcher), and
my JSP pages are hidden under /WEB-INF/jsp/*

Since Spring renders views using the Servlet request dispatcher's
include method, this means my custom content type filter needed the
following configuration:

<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/flow/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/WEB-INF/jsp/*</url-pattern>
<dispatcher>ERROR</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

Yes, the latter dispatchers were introduced in Java EE 5, so this does
mean if you are stuck with J2EE 1.4 or earlier there might not be any
solution to using SiteMesh with UTF-8 characters, at least with the
same mix of technologies as I'm using.

PS. I hope you do get chance to support SiteMesh 2 for the next year
whilst finishing off SiteMesh 3. It's a great shame to see mature and
widely used open source projects disappear, especially as even in this
day and age there are still no other similar solutions

cjn

srinivasan ravi

unread,
Jun 4, 2012, 4:42:16 AM6/4/12
to sitemes...@googlegroups.com
Hi
Have you tried this with chinese characters?My page displays chinese characters correctly for the first time it loads.From the second time these chinese characters are changed to tsomething like this
 
å ˆè‚¥å¸‚çˆ±å¿ƒå®¶åº­ç”¨å“ æœ‰é™ å…¬å ¸ which was properly displayed the first time
Reply all
Reply to author
Forward
0 new messages