nutzam/nutz — Issue #151: nutz @Fail 视图跳转 ActionContext 变化了，无法获取出错消息。
Author: cnyangqi
Created: 2012-02-08 05:05:38+00:00
State: open

@At("/upload/normal")
@AdaptBy(args = {"ioc:upload"})
@Fail("->:/test")
public Object upload(@Param("imgFile") TempFile file, @Param("dir") String dirName) {

System.out.println("___________000______________" + Mvcs.getActionContext().hashCode());

if (file != null) {

System.out.println(file.getFile());

dirName = dirName != null ? dirName : "image";

HashMap extMap = new HashMap();
extMap.put("image", "gif,jpg,jpeg,png,bmp");
extMap.put("flash", "swf,flv");
extMap.put("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb");
extMap.put("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2");

String fileName = file.getMeta().getName();

// 检查扩展名
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
if (!Arrays. asList(extMap.get(dirName).split(",")).contains(fileExt)) {
Map re = new HashMap();
re.put("error", "1");
re.put("message", "上传文件扩展名是不允许的扩展名。\n只允许" + extMap.get(dirName) + "格式。");
return re;
}

}

return "";
}

@At
public void test() {

// Throwable throwable = Mvcs.getActionContext().getError();

System.out.println("___________+++______________" + Mvcs.getActionContext().hashCode());

}

说明：
uploadFileContext里配置了“maxFileSize : 1048576”，当文件大小超过1M的时候，想自行拦截处理，封装一个JSON发送到前台JS框架。