我正在尝试使用primefaces上传文件组件导入csv文件,导入一些像€这样的特殊字符无法正确显示。
csv文件的原始编码不是utf-8
我的web.xml
<filter>
<filter-name>CharacterEncoding</filter-name>
<filter-class>com.filter.util.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncoding</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
我的表格:
<h:form id="uploadForm" enctype="multipart/form-data;charset=UTF-8">
我的输入文件上传:
< p:fileUpload id="uploadFileParamBtn" auto="true fileUploadListener="{myController.handleFileUpload}" label="upload"
allowTypes="/(\.|\/)(csv)$/" sizeLimit="10000000" />
我的过滤器类:
public class CharacterEncodingFilter implements Filter {
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws ServletException, IOException {
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
request.setCharacterEncoding(StandardCharsets.UTF_8.name());
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
@Override
public void init(final FilterConfig arg0) throws ServletException {
}
}
在jboss standlone.xml中:
<system-properties>
<property name="file.encoding" value="UTF-8"/>
<property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
</system-properties>
primfaces 5.3
JSF 2.0
的JBoss-EAP-6.2
提前感谢您的帮助