2015-09-11 22 views
1

我知道如何將文件上傳到action類,但我的要求不同。我有一個pojo-s列表,其中每個pojo都包含一個名爲file的字段。如何將文件上傳到在Struts 2的action類中設置的bean

例如: -

public class Pojo{ 

    private int pk; 
    private File file; 

    //setters and getters 
} 

在我的動作類: -

public class MyAction{ 

     private List<Pojo> pojos; 
     //setter getter 
} 

從我的jsp當我選擇一個文件,說上傳它必須設置爲POJO的「文件」屬性。我怎麼做?我完全知道如何直接上傳到操作類,但現在它已經不同了。該文件必須去並且坐在Pojo類文件屬性中。我怎樣才能做到這一點?

回答

0

關於上傳多個文件的詳細信息是described here

當您上傳一個或多個文件時,您可以指向操作屬性或property of an action's object中的屬性(單個或集合)。

缺少的唯一部分是JSP,您只需使用點符號來指定對象層次結構。另外不要忘記所有需要的getter和setter,以及contentType/fileName屬性。

POJO

public class Pojo{ 

    private int pk; 
    private File file; 
    private String fileContentType; 
    private String fileFileName;  

    // Getters and Setters 
} 

行動

public class MyAction{  
    private List<Pojo> pojos; // Getter and Setter 
} 

JSP

<s:file name="pojos.file" multiple="multiple" /> 
相關問題