[英]Mojarra 2.2.3 encoding request parameters
Problems started when I upgraded Mojarra from 2.2.1 to 2.2.3 (JBoss Wildfly Alpha to Beta). 当我将Mojarra从2.2.1升级到2.2.3 (JBoss Wildfly Alpha到Beta) 时,问题就出现了 。
When I try to submit a form (POST) with special characters (polish letters) they aren't properly UTF-8 encoded. 当我尝试提交带有特殊字符(波兰语字母)的表单(POST)时,它们不能正确地进行UTF-8编码。
What I have done? 我做了什么?
Wrote a filter 写了一个过滤器
@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; } }
Every XHTML contains a line 每个XHTML都包含一行
<?xml version="1.0" encoding="UTF-8"?>
Layout also contains information about encoding 布局还包含有关编码的信息
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Added properties to standalone.xml 添加了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"/>
Logs in console when debugging request parameters from filter 从过滤器调试请求参数时登录控制台
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 preview in browser 在浏览器中请求预览
How I initialize JSF page 我如何初始化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>
Finally I'm still ending with improper encoding: 最后我还是以不正确的编码结束:
The problem was in Undertow encoding. 问题出在Undertow编码中。
Solution here: https://issues.jboss.org/browse/WFLY-2533 解决方案: https : //issues.jboss.org/browse/WFLY-2533
here is a Bug about this: 这是关于这个的Bug:
https://issues.jboss.org/browse/WFLY-2550 https://issues.jboss.org/browse/WFLY-2550
and here is one possible solution: 这是一个可能的解决方案:
add this after your filter in web.xml: 在web.xml中过滤后添加:
<filter-mapping>
<filter-name>CDI Conversation Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
as described here: 如下所述:
http://weld.cdi-spec.org/documentation/#3 http://weld.cdi-spec.org/documentation/#3
Regards, 问候,
Martin 马丁
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.