2012-07-14 12 views
1

我知道有很多jquery插件可用於文件上傳。但它只是顯示我們如何將它添加到jsp頁面中。但是我想知道我們如何才能處理在後端使用這些插件選擇的文件。例如,我在struts2中使用spring。因此,我想從我的jsp中將這些文件發送到我的操作類中,並將其存儲在服務器位置中。任何機構知道如何才能我這樣做。在jsp頁面中使用文件上傳jquery插件與strut動作類

回答

1

userImage<file>標籤

public class FileUploadAction extends ActionSupport{ 
     private File userImage; 
     private String userImageContentType; 
     private String userImageFileName; 

     private HttpServletRequest servletRequest; 

     public String execute() { 
      try { 
       String filePath = "yourPath"; 
       File fileToCreate = new File(filePath, this.userImageFileName); 

       FileUtils.copyFile(this.userImage, fileToCreate); 
      } catch (Exception e) { 
       e.printStackTrace(); 
       addActionError(e.getMessage()); 

       return INPUT; 
      } 
      return SUCCESS; 
     } 

    } 

的名字從this tutorial

This tutorial解釋了多個文件上傳usinf列表

+0

正在擴大crudActionSupport.Can我用上面的方法在我的動作類 – elvisanandkumar 2012-07-14 14:45:38

+0

我沒有嘗試過。你爲什麼不試一試 – anu 2012-07-14 14:53:13

相關問題