【问题标题】:using PrimeFaces upload file get garbled character使用 PrimeFaces 上传文件得到乱码
【发布时间】:2014-03-28 23:32:08
【问题描述】:

我使用primeface上传文件,关于表单的代码是这样的

<h:form enctype="multipart/form-data">
    ....
    <pf:inputTextare value="#{bean.text}"/>
    <pf:fileupload value="#{bean.file}" mode="sample"/>
    <pf:commandButton actionLister="#{bean.save}"/>
    ....
</h:form>

bean 代码就这么简单

public class bean{
    private String text;
    private UploadedFile file;
    //getter and setter methods...
    public void save(){
       //save file and text in DB
    }
}

当我使用 enctype="multipart/form-data" 时,我可以成功上传文件。但文字是非法字符。但是当我不在表单中使用“multipart/form-data”时,文本字符是正确的,但文件无法上传。 我搜索了“multipart/form-data”,上传文件“multipart/form-data”对于表单是必需的(可能不正确:)),但是我该如何解决非法字符?(或者你能告诉我还有另一种上传文件的方法,没有“multipart/form-data”?)

【问题讨论】:

    标签: forms jsf file-upload primefaces


    【解决方案1】:

    我已经解决了这个问题,在管理 bean 中,您需要从表单中获得转码。像这样。

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

    【讨论】:

      猜你喜欢
      • 2017-03-13
      • 2012-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多