private Boolean checkImg(File upload) {
// 上传图片之前先判断图片大小
Boolean flag = false;
String info = "";
if (upload == null) {
info = "<script>alert('添加失败,上传文件不存在');history.back();</script>";
} else if (upload.length() > MERIMG_MAX_SIZE) {
info = "<script>alert('添加失败,上传文件大小不能超过20M!');history.back();</script>";
} else if (upload.length() == 0) {
info = "<script>alert('添加失败,上传文件大小为0');history.back();</script>";
} else {
flag = true;
}
if (!flag) {
ServletActionContext.getResponse().setContentType(
"text/html;charset=UTF-8");
PrintWriter out;
try {
out = ServletActionContext.getResponse().getWriter();
out.print(info);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return flag;
}
转载于:https://my.oschina.net/u/1582930/blog/350454