struts2上传文件非根对象上传报错
当遇到非根对象的时候 文件上传
struts2会给我们报一个没有ContentType 没有FileName的方法的方法
警告: Error setting expression 'person.attachment' with value '[Ljava.io.File;@15772fd'
ognl.OgnlException: target is null for setProperty(null, "attachment", [Ljava.io.File;@15772fd)
警告: Error setting expression 'person.attachmentContentType' with value '[Ljava.lang.String;@1a28b5c'
ognl.OgnlException: target is null for setProperty(null, "attachmentContentType", [Ljava.lang.String;@1a28b5c)
举例:
class Person{
private String name;
private File attachment;
get....
set.....
}
public class UserAction implements ModelDriven{
private Person person;
@Override
public Object getModel() {
if(user==null){
user = new User();
}
return user;
}
public String add(){
//System.out.println("添加user");
return "success";
}
}
界面
<form action="sb/user!add.do" enctype="multipart/form-data" method="post">
<input type="text" name="person.name"/>
<input type="file" name="person.attachment"/>
<input type="submit" value="登录"/>
</form>
对于非根对象插入数据

浙公网安备 33010602011771号