使用utf8字符过滤器的primfaces fileupload过滤器 [英] primefaces fileupload filter with utf8 characters filter

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

问题描述

我在primfaces 3中遇到utf-8编码的问题,但使用(在web.xml中添加字符编码过滤器),我的问题解决了。但我有另一个过滤器在我的web.xml中的primefaces fileupload。在有文件上传的页面,即使没有上传任何东西,我的字符编码过滤器不工作,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()已在< code> web.xml 之前映射到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()));

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

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字符过滤器的primfaces fileupload过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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