警告: Error setting expression 'uploadFile' with value '[Ljava.io.File;@e289cb'
ognl.OgnlException: uploadFile [java.lang.IllegalArgumentException: argument type mismatch]
at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:103)
at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162)
at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2315)
。。。。。。
UserAction:
private Byte[] uploadFile;
public String add(){
System.out.println(fileName);
return "success";
}
public Byte[] getUploadFile() {
return uploadFile;
}
public void setUploadFile(Byte[] uploadFile) {
this.uploadFile = uploadFile;
}
ByteArrayConverter:
public class ByteArrayConverter extends DefaultTypeConverter {
@Override
public Object convertValue(Map<String, Object> context, Object value, Class toType) {
File[] files = (File[])value;
try {
return FileUtils.readFileToByteArray(files[0]);
} catch (IOException e) {
e.printStackTrace();
}
return "mei utils";
}
xhy/shjc/UserAction-conversion.properties:
uploadFile=xhy.shjc.ByteArrayConverter
------解决方案--------------------
有错误提示 啊:
ognl.OgnlException: uploadFile [java.lang.IllegalArgumentException: argument type mismatch]
类型不匹配。
------解决方案--------------------
你传的东西可能不支持byte[]类型,你可以在页面限制一下上传的文件后缀,比如支持.txt,.jpg等等
------解决方案--------------------
http://www.oschina.net/code/snippet_105133_2208
------解决方案--------------------
setPossibleProperty
检查各个属性。