extjs4,spring mvc3上传文件(二)

2014-11-24 01:40:04 · 作者: · 浏览: 4
on e) {
System.out.println(e.getMessage());
return null;
}
}
//set extjs return - sucsess
extjsFormResult.setSuccess(true);

return extjsFormResult.toString();
}

/* **保存文件

* @param stream
* @param path
* @param filename
* @throws IOException
*/
public void SaveFileFromInputStream(InputStream stream,String path,String filename) throws IOException
{
FileOutputStream fs=new FileOutputStream(path + "/"+ filename);
byte[] buffer=new byte[1024*1024];
int bytesum = 0;
int byteread = 0;
while ((byteread=stream.read())!=-1)
{
bytesum+=byteread;

fs.write(buffer,0,byteread);
fs.flush();

}
fs.close();
stream.close();
}

可以看到,当出现错误时,extjsFormResult.setSuccess(false);

return extjsFormResult.toString();
这两句返回给前端ext js处理。
最后就是配置MVC了

Java代码














设置文件大小限制

一个很奇怪的问题是,在ie 7下,好象有点问题,待解决,但在firefox和chrome下都没问题,这个extjs 真怪,不用ext,普通的spring mvc是没问题的哦