-
1. Re: How to set charset for my web application?
sfcoy Mar 21, 2013 7:18 AM (in response to ybxiang.china)The platform independent way to do this is to use ServletRequest.setCharacterEncoding(java.lang.String) before processing the request parameters.
If you're using a framework that interprets the request for you, you can use a servlet filter instead:
{code:java}public class CharacterEncodingFilter implements javax.servlet.Filter {
...
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException,
ServletException {
request.setCharacterEncoding("UTF-8");
filterChain.doFilter(request, response);
}
}{code}
-
2. Re: How to set charset for my web application?
ybxiang.china Mar 21, 2013 10:04 AM (in response to sfcoy)Thank you sir, you are right.
I implemented the filter just now, it works well now.
I had thought there is a parameter to configure such things in JSF2 framework.
-
3. Re: How to set charset for my web application?
trollfar Sep 17, 2013 10:19 AM (in response to sfcoy)Hi, Does not work for me, no clue why. Put the filter in, put a breakpoint in it and verified that it got executed, but still got parameters interpereted as if they were ISO 8859-1, running jboss-as-7.1.1.Final on windows. What solved it was adding
-Dorg.apache.catalina.connector.URI_ENCODING=UTF-8 to the java boot. Right or wrong, but it worked.
-
4. Re: How to set charset for my web application?
ybxiang.china Sep 17, 2013 8:37 PM (in response to trollfar)but still got parameters interpereted as if they were ISO 8859-1
~~~~~There are many places to configure the UTF-8. I have summarized all of them here: 开发基于JBoss AS 7.2.0的Java EE程序 - 08.如何设置UTF-8
-
5. Re: How to set charset for my web application?
kenail2002 Sep 18, 2013 12:09 PM (in response to ybxiang.china)Good summary.But may be need writting in English also.