Stripes中上传文件,如何使用DefaultMultipartWrapperFactory

发布于 2024-11-01 19:56:29 字数 1463 浏览 0 评论 0原文

我正在尝试开发一个小型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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

知你几分 2024-11-08 19:56:29

看来您只是缺少 Commons FileUpload。尝试将其添加到您的类路径中,看看它是否有效。

Seems like you're simply missing Commons FileUpload. Try adding it to your classpath and see if it works.

So尛奶瓶 2024-11-08 19:56:29

我也遇到了同样的问题。
通过在 stripes Filters 中添加 init 参数解决了这个问题。

<init-param>
  <param-name>MultipartWrapper.Class</param-name>
  <param-value>net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper</param-value>
</init-param>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文