在JSF / facelet中访问请求参数的过滤器导致错误的编码 [英] Filter with access to request parameter in JSF / facelets leads to wrong encoding

查看:237
本文介绍了在JSF / facelet中访问请求参数的过滤器导致错误的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临以下问题/ bug
(对于用例:我添加了一个log4j过滤器,因为它使得良好的日志记录可用,请参阅此处了解详情)

I'm facing the following problem / bug (for the use case: I added a log4j filter since it makes nice logging available, see here for details)

这是关于当访问过滤器中的请求参数时编码的什么发生:
所有üäöéèàà等变成üÃÃÃÃÃÃÃÃÃÃÃ和他们的丑恶的朋友。
如果我不访问请求参数,它会正常工作。

This is about what the heck happens to the encoding when accessing a request parameter in a filter: All ü ä ö é è à etc turn into ü ä ö é è à and their ugly friends. If I don't access the request parameter it works fine.

这会导致整个应用程序中出现错误的字符

this leads to wrong characters in the whole application

public class Log4jDiagnosticFilter implements Filter {

    public void init(FilterConfig arg0) throws ServletException {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
            ServletException {
                String requestId=request.getParameter("LOGID");
                chain.doFilter(request, response);
        }
}

不访问请求参数时,所有字符都很好。

All characters are fine when not accessing the request parameters.

有我缺少的东西吗?有不同的方法吗?

is there something I am missing? Is there a different way to do it?

btw我们使用java 1.5和jsf 1.2

btw we are using java 1.5 and jsf 1.2

推荐答案

你显然有另一个过滤器 request.setCharacterEncoding(UTF-8)。这是一个一次性任务,它要求请求主体尚未解析。但是调用 getParameter()将开始解析整个请求体。因此,如果你把这个日志过滤器放在编码过滤器的前面,那么应用程序的剩余部分检索正确编码的字符太晚了。

You have apparently another filter which does request.setCharacterEncoding("UTF-8"). This is an one-time task and it requires that the request body is not been parsed yet. But calling getParameter() will start parsing the entire request body. So if you put this logging filter in front of the encoding filter, then it's too late for the remnant of the application to retrieve properly encoded characters.

交换过滤器的顺序 web.xml ,并确保字符编码过滤器位于以任何方式访问请求正文的任何​​其他过滤器之前。

Swap the filter order in web.xml and make sure that the character encoding filter is placed before any other filter which accesses the request body in any way.

这篇关于在JSF / facelet中访问请求参数的过滤器导致错误的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆