我使用的是Struts2和Apache POI jar。在我的项目中,我必须上传一个Excel文件,在我的行动中,我必须读取这个Excel文件。作为准备工作,我使用了Struts2文件上传拦截器。除了一件事之外,一切都运行得很好。如何使用Struts2拦截器检查Excel文件是否为空?是否可以检查上传文件是否为空?
发布于 2012-12-08 16:53:49
1,在Interceptor本身中,你可以调用定制的类,在那里你可以检查。
2 .检查文件大小,同时在配置文件中提及大小。
发布于 2012-12-08 18:15:05
您可以在上传文件的操作中执行此操作:
public class UploadAction extends ActionSupport
{
File upload;
//Other properties
public String execute(){
if (!fileValid()){
return INPUT;
}
//Your stuff...
return SUCCESS;
}
private boolean fileValid(){
return upload != null;
//You can do other checks here...
}
}https://stackoverflow.com/questions/13775875
复制相似问题