Stripes中上传文件,如何使用DefaultMultipartWrapperFactory
我正在尝试开发一个小型Stripes项目,允许用户加载文件,ActionBean的基本实现如下所示:
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);
}
}
正如我所说,非常简单,jsp是这样的,也非常简单:
<s:form beanclass="stripesbook.action.UploadActionBean" enctype="multipart-form/data">
<s:file name="fileBean"/>
<s:submit name="upload" value="upload"/>
该应用程序似乎部署正确,应用程序启动没有问题,但一旦我单击上传,我就会收到以下异常:
net.sourceforge.stripes.exception.StripesRuntimeException: Could not construct a MultipartWrapper for the current request.
它来自 nullPointerException:
at net.sourceforge.stripes.controller.multipart.DefaultMultipartWrapperFactory.wrap(DefaultMultipartWrapperFactory.java:151)
我知道我必须使用 DefaultMultipartWrapperFactory 类的 wrap() 方法,但如何呢? 我正在努力寻找解释该问题的文档,但没有结果,有什么建议吗?
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 nullPointerException:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您只是缺少 Commons FileUpload。尝试将其添加到您的类路径中,看看它是否有效。
Seems like you're simply missing Commons FileUpload. Try adding it to your classpath and see if it works.
我也遇到了同样的问题。
通过在 stripes Filters 中添加 init 参数解决了这个问题。
I had got the same problem.
Got resolved by adding init param in stripes Filters.