Jsf primefaces上载程序,上载多个文件问题

Jsf primefaces上载程序,上载多个文件问题,jsf,file-upload,jsf-2,primefaces,Jsf,File Upload,Jsf 2,Primefaces,我将jsf2与PrimeFaces3.5一起使用 我在我的网站上添加了文件上传组件,如下所示: <p:panel toggleable="true" id="panel2"><p:fileUpload value="#{MyBeanObj.fileObj}" mode="simple" required="true" /></p:panel> 我怎样才能摆脱这个异常 提前感谢….我通过在上传文件后添加file=null并将返回字符串设置到同一页面来解决此问

我将jsf2与PrimeFaces3.5一起使用

我在我的网站上添加了文件上传组件,如下所示:

<p:panel toggleable="true" id="panel2"><p:fileUpload value="#{MyBeanObj.fileObj}"  mode="simple" required="true" /></p:panel>
我怎样才能摆脱这个异常


提前感谢….

我通过在上传文件后添加file=null并将返回字符串设置到同一页面来解决此问题!所以我的后盾变成这样:

public String addNewPhoto(){


try{


if(file!=null){
    boolean issuccess=false;
    String fileName = file.getFileName().replaceAll("\\s+", "");


    destination = "/images/";
 createDestination(destination);
 newPhoto.setPhotoPat(fileName);


 // Do what you want with the file       
 try {

 copyFile(fileName, file.getInputstream());


 } 
 catch (Exception e) {

 //loging ...
  } 


newPhoto=null;
newPhoto=new ProductPhotosDto();

file=null;


return "uploadPage.jsf";

}

希望这对任何人都有帮助。。谢谢

我也有类似的问题,但我的问题只是偶尔/随机发生。我会尝试使用你的解决方案,然后带着反馈回来。这似乎没有任何区别。我将尝试使用PF 4.0,因为文件上载已完全重写。谢谢更新我:。。如果这件事和你一起解决了,你能告诉我吗?到目前为止,这件事随机发生在我身上。不客气。我发现并想试试这个:它实际上很有意义,所以我会试试看。
public void addNewPhoto(){


    try{


    if(file!=null){
        boolean issuccess=false;
        String fileName = file.getFileName().replaceAll("\\s+", "");


        destination = "/images/";
     createDestination(destination);
     newPhoto.setPhotoPat(fileName);


     // Do what you want with the file       
     try {

     copyFile(fileName, file.getInputstream());


     } 
     catch (Exception e) {

     //loging ...
      } 


    newPhoto=null;
    newPhoto=new ProductPhotosDto();






}

public void copyFile(String fileName, InputStream in) {
      try {



      OutputStream out = new FileOutputStream(new File(destination+ fileName));

      int read = 0;
      byte[] bytes = new byte[1024];

      while ((read = in.read(bytes)) != -1) {
      out.write(bytes, 0, read);
      }

      in.close();
      out.flush();
      out.close();

      //system.out.println("New file created!");
     } catch (IOException e) {
        //log
      }
      }
public String addNewPhoto(){


try{


if(file!=null){
    boolean issuccess=false;
    String fileName = file.getFileName().replaceAll("\\s+", "");


    destination = "/images/";
 createDestination(destination);
 newPhoto.setPhotoPat(fileName);


 // Do what you want with the file       
 try {

 copyFile(fileName, file.getInputstream());


 } 
 catch (Exception e) {

 //loging ...
  } 


newPhoto=null;
newPhoto=new ProductPhotosDto();

file=null;


return "uploadPage.jsf";

}