Upload file in Stripes, how to use DefaultMultipartWrapperFactory
I'm trying to develop a small Stripes project that allows the user to uoload files, the basic implementation of the ActionBean looks like so:
public class UploadActionBean extends BaseActionBean{
private FileBean fileBean;
private final String fileUpload="/WEB-INF/jsp/file-upload.jsp";
public void setFileBean(FileBean fileBean){
this.fileBean=fileBean;
}
public FileBean getFileBean(){
return this.fileBean;
}
@DefaultHandler
public Resolution goToFile(){
return new ForwardResolution(fileUpload);
}
public Resolution upload() throws IOException{
System.out.println(fileBean.getFileName());
fileBean.getContentType();
fileBean.getSize();
fileBean.save(new File("/Users/enricoiorio/Desktop"));
return new ForwardResolution(fileUpload);
}
}
As i said is very simple, the jsp is like this, also very simple:
<s:form beanclass="stripesbook.action.UploadActionBean" enctype="multipart-form/data">
<s:file name="fileBean"/>
<s:submit name="upload" value="upload"/>
The app seems to deploy correctly, the app starts with no problem but as soon as i click on upload i get the following exception:
net.sourceforge.stripes.exception.StripesRuntimeException: Could not construct a MultipartWrapper for the current request.
which arrives from a nullPoi开发者_开发知识库nterException:
at net.sourceforge.stripes.controller.multipart.DefaultMultipartWrapperFactory.wrap(DefaultMultipartWrapperFactory.java:151)
I understand that i have to use the wrap() method of the DefaultMultipartWrapperFactory class, but how? I'm struggling trying to find a documentation that explains that but no results, any advise?
Seems like you're simply missing Commons FileUpload. Try adding it to your classpath and see if it works.
I had got the same problem. Got resolved by adding init param in stripes Filters.
<init-param>
<param-name>MultipartWrapper.Class</param-name>
<param-value>net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper</param-value>
</init-param>
精彩评论