jifnal catch异常后为为什么不能setAttr

try {

List<UploadFile> attachList = getFiles("notice", 100 * 1024 * 1024, "utf-8");

for (int i = 0; i < attachList.size(); i++) {

String imagename = "";

String filename = attachList.get(i).getOriginalFileName();

String suffix = filename.substring(filename.indexOf("."), filename.length());

String fileMd5 = MD5

.getMD5Str(filename.substring(0, filename.indexOf(".")) + "/" + new Date().getTime());

imagename = fileMd5 + suffix;

attachList.get(i).getFile().renameTo(new File(attachList.get(i).getUploadPath(), imagename));

Attachment attachment = new Attachment();

attachment.set("type", 0);

attachment.set("title", filename);

attachment.set("path", imagename);

attachment.set("download", 0);

if (noticeService.saveAttachment(attachment)) {

list.add(attachment);

} else {

setAttr("result", ResultSign.Fail.getState());

setAttr("msg", "保存失败");

}

}

setAttr("result", ResultSign.Success.getState());

setAttr("msg", "添加附件成功");

setAttr("AttachmentList", new AttachmentList(list));

} catch (Exception e) {

e.printStackTrace();

setAttr("result", 101);

setAttr("msg", "附件大小超出规定范围(0-100M)");

}


评论区

hanweihanwei

2017-12-03 12:12

我上传超限文件后catch块内的代码确实执行了,getRequest().getAttrubute("msg")确实也是输入的值,但是为什么就不能传到前台去。为空数据

liuzy666

2017-12-03 19:29

这也行,都抛出异常了还想传前端啊?

hanweihanwei

2017-12-03 19:33

@liuzy666 我catch块处理了异常为什么不能传前端

热门分享

扫码入社