0
我想通過註解設置FileUploadInterceptor上的動作:如何使用FileUploadInterceptor與Struts2的Convention插件
@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一樣,這個屬性也不會被填充。
Basicaly,這個工程:
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 {...
@Max沒問題;如果它解決了這個問題,考慮upvoting或[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) - 但只有它有幫助! – 2012-02-09 19:26:34
感謝您的回答。但也許我還不夠清楚。 Basicaly,這個工程: 公共類UploadAction擴展了ActionSupport {... 但是,這並不工作: @InterceptorRefs({ @InterceptorRef( 「文件上傳」) }) 公共類UploadAction擴展了ActionSupport {... 或 @InterceptorRefs({ @InterceptorRef( 「文件上傳」), @InterceptorRef( 「myOtherinterceptor」) }) 公共類UploadAction延伸ActionSupport的{... 也許對配置文件使用FileUploadInterceptor有限制,並且不支持通過註釋約定實現的攔截器? – Max 2012-02-09 19:46:58
我完全無法閱讀 - 如果您有其他信息,請更新您的問題。不過,我仍然沒有看到那裏的任何默認S2攔截器。 – 2012-02-09 19:50:28