如何将文件上传到在 Struts 中的操作 class 中设置的 bean 2
How to upload file to bean that is set in action class in Struts 2
我知道如何将文件上传到操作中 class 但我的要求不同。我有一个 pojo-s 列表,其中每个 pojo 都包含一个名为文件的字段。
例如:-
public class Pojo{
private int pk;
private File file;
//setters and getters
}
在我的行动中class:-
public class MyAction{
private List<Pojo> pojos;
//setter getter
}
来自我的 jsp 当我 select 一个文件并说上传它必须设置到 Pojo "file" 属性。我怎么做?我完全了解如何直接上传到操作 class,但现在不同了。该文件必须放在 Pojo class 文件 属性 中。我怎样才能做到这一点?
关于上传多个文件的详细信息是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" />
我知道如何将文件上传到操作中 class 但我的要求不同。我有一个 pojo-s 列表,其中每个 pojo 都包含一个名为文件的字段。
例如:-
public class Pojo{
private int pk;
private File file;
//setters and getters
}
在我的行动中class:-
public class MyAction{
private List<Pojo> pojos;
//setter getter
}
来自我的 jsp 当我 select 一个文件并说上传它必须设置到 Pojo "file" 属性。我怎么做?我完全了解如何直接上传到操作 class,但现在不同了。该文件必须放在 Pojo class 文件 属性 中。我怎样才能做到这一点?
关于上传多个文件的详细信息是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" />