带有 utf8 字符过滤器的 primefaces 文件上传过滤器 [英] primefaces fileupload filter with utf8 characters filter

查看:22
本文介绍了带有 utf8 字符过滤器的 primefaces 文件上传过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 primefaces 3 中使用 utf-8 编码有问题.但是 这个(在web.xml中为字符编码添加过滤器),我的问题解决了.但是我的 web.xml 中有另一个用于primefaces 文件上传的过滤器.在有文件上传的页面,即使没有上传任何东西,我的字符编码过滤器也不起作用,utf-8 字符集的值未知,就像没有上传过滤器一样.我怎样才能一起使用这个过滤器?

I have a problem with utf-8 encoding in primefaces 3. but with this (adding filter for character encoding in web.xml), my problem solved. But I have another filter for primefaces fileupload in my web.xml. In pages that there is fileupload, even without uploading anything, my character encoding filter don't work and utf-8 character sets with unknown values, just like when there was no filter for uploading. How I can use this filter together?

推荐答案

这是 PrimeFaces 的 MultipartRequest 中的一个错误.它对表单字段使用平台默认字符编码,而不是在 HTTP servlet 请求中设置的字符编码过滤器中的 HttpServletRequest#setCharacterEncoding()(我假设它已映射到 web.xml before PrimeFaces FileUploadFilter).

This is a bug in PrimeFaces' MultipartRequest. It's using the platform default character encoding for form fields instead of the one set in the HTTP servlet request as done by HttpServletRequest#setCharacterEncoding() in your character encoding filter (which I assume is been mapped in web.xml before the PrimeFaces FileUploadFilter).

基本上是 PrimeFaces 3.3 中 MultipartRequest 的第 85 和 88 行

Basically, line 85 and 88 of MultipartRequest in PrimeFaces 3.3

formParams.get(item.getFieldName()).add(item.getString());
// ...
items.add(item.getString());

需要修改如下

formParams.get(item.getFieldName()).add(item.getString(getCharacterEncoding()));
// ...
items.add(item.getString(getCharacterEncoding()));

我已将其报告为问题 4266.同时,假设服务器平台默认编码为ISO-8859-1,您最好的办法是手动修复backing bean action方法中不正确的字符串编码,如下所示:

I have reported it as issue 4266. In the meanwhile, your best bet is to manually fix the incorrect string encoding in the backing bean action method as follows, assuming that the server platform default encoding is ISO-8859-1:

string = new String(string.getBytes("ISO-8859-1"), "UTF-8");

这篇关于带有 utf8 字符过滤器的 primefaces 文件上传过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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