开发者

Filter with access to request parameter in JSF / facelets leads to wrong encoding

开发者 https://www.devze.com 2023-03-07 01:52 出处:网络
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) 开发者_高级运维

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 we are using java 1.5 and jsf 1.2


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.

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.

0

精彩评论

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

关注公众号