Janne and Samuel,
Ok... I think there are some things that need to be clarified... b/c it
was a while since I set this up in Stripes... I hadn't realized I even
set it up.
Technically speaking yes - you are both correct -
request.setCharacterEncoding("UTF-8") is required and should be
performed if you are doing UTF-8 with a simple Servlet. However, as
StripesFilter is already in place one would hope you wouldn't have to
wrap yet another Servlet filter around it and clearly you don't.
Basically, in addition to the other things I mentioned there indeed is
one Stripes configuration that I set... by creating a custom
LocalePicker subclass that picks the character encoding "UTF-8"... and
dropping it the configured Stripes extensions folder... the relevant
code is as follows:
public class MyLocalePicker implements LocalePicker {
...
@Override
public final String pickCharacterEncoding(HttpServletRequest
request, Locale locale) {
return ("UTF-8");
}
}
And voila... all is well... and NO need for your additional Stripes
wrapper... why b/c the StripesFilter performs the following:
* String encoding =
this.configuration.getLocalePicker().pickCharacterEncoding(httpRequest,
locale);*
* if (encoding != null) {*
* httpRequest.setCharacterEncoding(encoding);*
log.debug("LocalePicker selected character encoding:
", encoding);
}
else {
log.debug("LocalePicker did not pick a character
encoding, using default: ",
httpRequest.getCharacterEncoding());
}
So, in fact we are golden via simple Stripes configuration vs. wrapping
a custom filter around the Stripes filter.
I had done this so long ago that I forgot I even did it. And yes,
technically the web browser should adhere to what its asked to use as
the encoding and sure older web browsers may have issues - problem is
what "older" means today is very unclear - so I agree this needs to be
done but let Stripes do it for you.
So the above should be added to my previous list :-)
Cheers,
--Nikolaos
Samuel Santos wrote:
Hi Daniil,
I've an old post about this topic at
http://www.samaxes.com/2006/12/java-and-utf-8-encoding/.
Hope it helps,
--
Samuel Santos
http://www.samaxes.com/
On Sat, Feb 5, 2011 at 8:16 AM, Janne Jalkanen
<janne.jalka...@ecyrd.com <mailto:janne.jalka...@ecyrd.com>> wrote:
Really??? A filter just to set character encoding??? Although I
imagine it would work isn't that a little sledge hammer-ish ;-)
I seem to recall it was the recommended practice.
Why not just put the following at the top of each of your JSPs
(or tweak as necessary):
<%@ page language="java" pageEncoding="UTF-8"
contentType="text/html;charset=UTF-8" %>
That will ensure your web page supports UTF-8.
No, it will just ensure that it outputs UTF-8; it does not say
anything about incoming request (which is what the
request.setCharacterEncoding() does.)
As far as Stripes is concerned you don't have to do anything for
it to support UTF-8... and Java retains all Strings in unicode so
no issue there either.
The problem stems from the fact that servlet spec says that the
default input encoding is ISO-8859-1. Especially older browsers do
not send the character encoding correctly, so you're better off
declaring the input encoding explicitly.
Please see Servlet specification version 2.5 Section SRV.3.9.
/Janne
------------------------------------------------------------------------------
The modern datacenter depends on network connectivity to access
resources
and provide services. The best practices for maximizing a physical
server's
connectivity to a physical network are well understood - see how these
rules translate into the virtual world?
http://p.sf.net/sfu/oracle-sfdevnlfb
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
<mailto:Stripes-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/stripes-users
------------------------------------------------------------------------------
The modern datacenter depends on network connectivity to access resources
and provide services. The best practices for maximizing a physical server's
connectivity to a physical network are well understood - see how these
rules translate into the virtual world?
http://p.sf.net/sfu/oracle-sfdevnlfb
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users