1

I know how to upload a file into the action class but my requirement is different. I have a list of pojo-s where each pojo contains a field called file.

for example:-

public class Pojo{

    private int pk;
    private File file;

   //setters and getters
}

In my action class:-

public class MyAction{

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

from my jsp when i select a file and say upload it has to set to the Pojo "file" property. how do i do that? I have complete idea of how to upload directly to the action class but now it is different. the file has to go and sit in the Pojo class file property. How can i do this?

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143

1 Answers1

0

The details about uploading multiple files are described here.

When you upload one or more files, you can point to the property (single or collection) both in an action property, or in a property of an action's object .

The only part missing is the JSP, where you simply need to use the dot notation to specify the object hierarchy. Also don't forget all the getters and setters needed, and the contentType / fileName properties too.

POJO

public class Pojo{

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

    // Getters and Setters
}

Action

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

JSP

<s:file name="pojos.file" multiple="multiple" />
Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243