Mojarra 2.2.3编码请求参数

时间:2013-11-07 14:18:44

标签: jsf encoding jboss mojarra

当我将Mojarra从2.2.1升级到2.2.3 (JBoss Wildfly Alpha到Beta)时出现了问题。

当我尝试提交带有特殊字符(波兰语字母)的表单(POST)时,它们不能正确地进行UTF-8编码。

我做了什么?

  • 写了一个过滤器

    @WebFilter(urlPatterns = "/*", initParams = { @WebInitParam(name = "ignore", value = "true" ), @WebInitParam(name = "encoding", value = "UTF-8") })
    public class CharacterEncodingFilter implements Filter {
    
        private String encoding = null;
        private FilterConfig filterConfig;
    
        // Should a character encoding specified by client be ignored
        private boolean ignore = true;
    
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
            this.filterConfig = filterConfig;
            this.encoding = filterConfig.getInitParameter("encoding");
            String value = filterConfig.getInitParameter("ignore");
    
            this.ignore = ((value == null) || value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"));
        }
    
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    
            if ((ignore || (request.getCharacterEncoding() == null)) && (encoding != null)) {
                request.setCharacterEncoding(encoding);
                response.setCharacterEncoding(encoding);
            }
    
            chain.doFilter(request, response);
        }
    
        @Override
        public void destroy() {
            this.encoding = null;
            this.filterConfig = null;
        }
    }
    
  • 每个XHTML都包含一行

    <?xml version="1.0" encoding="UTF-8"?>

  • 布局还包含有关编码的信息

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

  • 为standalone.xml添加了属性

    <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
    <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
    <property name="file.encoding" value="UTF-8"/>
    
  • 从过滤器

    调试请求参数时登录控制台

    index_form:people: Tischner PrzemysÅaw

    index_form:j_idt66: index_form:j_idt66

    index_form: index_form

    index_form:dbId: 2881850

    javax.faces.ViewState: 2748560203387116963:2575775533048879716

  • 在浏览器中请求预览 Request in Chrome

  • 我如何初始化JSF页面

    <f:metadata>
        <f:viewParam name="name" value="#{followNewView.name}" />
        <f:viewParam name="company" value="#{followNewView.company}" />
        <f:viewParam name="companyURL" value="#{followNewView.companyURL}" />
        <f:viewAction action="#{followNewView.init}" />
    </f:metadata>
    

最后我还是以不正确的编码结束: enter image description here

2 个答案:

答案 0 :(得分:2)

问题在于Undertow编码。

此处的解决方案:https://issues.jboss.org/browse/WFLY-2533

答案 1 :(得分:1)

这是关于此的Bug:

https://issues.jboss.org/browse/WFLY-2550

这是一个可能的解决方案:

在web.xml中过滤后添加:

<filter-mapping>
    <filter-name>CDI Conversation Filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

如下所述:

http://weld.cdi-spec.org/documentation/#3

此致

马丁