开发者

Glassfish JSF 2.0 charset problem

I'm working on a project developed with JSF 2.0 (Mojarra 2.0.3) front end and deployed on Glassfish v.3.0.1 server. Application must accept ISO-8859-2 charset and write data to MySql database. To problem is that data is not in right charset. The request Http header has attribute value:

content-type: application/x-www-form-urlencoded; charset=UTF-8

The problem is not with response, since da开发者_如何学JAVAta can be displayed correctly when read from database. Also, MySql connection URL should be correct because it is set for latin2 collaction. I even tried with creating custom filter, but without any result.

Any ideas how can I accomplish to accept correct charset?

Thanks in advance.


You can always force ISO-8859-2 encoding by creating a Filter and defining it in your web.xml. At a bare minimum, the Filter should have:

public class CustomFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
       try {
          if ((request instanceof HttpServletRequest)
              && (response instanceof HttpServletResponse))  {
              request.setCharacterEncoding("ISO-8859-2");
              response.setContentType("text/html; charset=ISO-8859-2")
           }
           chain.doFilter(request, response);
        } catch (Exception e) {
           // Do your logging here
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜