我正在尝试通过注释在操作上设置 FileUploadInterceptor :
@Namespace("/")
@ParentPackage("my-package")
@Result(name = "success", location = "/WEB-INF/jsp/result.jsp")
@InterceptorRef("fileUpload")
public class UploadAction extends ActionSupport {
private File upload;
private String uploadContentType;
private String uploadFileName;
public void setUpload(File upload) {
this.upload = upload;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
public File getUpload() {
return this.upload;
}
public String getUploadContentType() {
return this.uploadContentType;
}
public String getUploadFileName() {
return this.uploadFileName;
}
@Override
@Action("doUpload")
public String execute()
{
System.out.println("Upload ok : " + (this.upload != null));
return SUCCESS;
}
}
我的问题是它只有在我没有在动作类上设置任何拦截器时才有效。一旦我设置了一个拦截器,即使是像上面这样的 FileUploadInterceptor,属性也不会被填充。
基本上,这有效:
public class UploadAction extends ActionSupport {...
但这不起作用:
@InterceptorRefs({
@InterceptorRef("fileUpload")
})
public class UploadAction extends ActionSupport {...
或者
@InterceptorRefs({
@InterceptorRef("fileUpload"),
@InterceptorRef("myOtherinterceptor")
})
public class UploadAction extends ActionSupport {...
我发现 !解决方案是:
@InterceptorRefs({
@InterceptorRef("fileUpload"),
@InterceptorRef("basicStack")
})
public class UploadAction extends ActionSupport {...