Apache 公共文件上传 FileItemIterator hasNext() 返回 false [英] Apache commons fileupload FileItemIterator hasNext() returns false

查看:37
本文介绍了Apache 公共文件上传 FileItemIterator hasNext() 返回 false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 apache commons 文件上传流 api.但是 FileItemIterator FileItemIterator iter = upload.getItemIterator(request); 在它的 hasNext() iter.hasNext() 中返回 false 有什么问题?

I'm using the apache commons fileupload stream api. But the FileItemIterator FileItemIterator iter = upload.getItemIterator(request); returns false in its hasNext() iter.hasNext() What is wrong with this?

代码和web part如下:

The code and the web part is as follows:

  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

    /**
     * Apache commons file upload method will be used
     */
    // Check that we have a file upload request
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);

    if (isMultipart) {
        try {
            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload();
            // Parse the request
            FileItemIterator iter = upload.getItemIterator(request);

            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                String name = item.getFieldName();
                InputStream stream = item.openStream();
                if (item.isFormField()) {
                    System.out.println("Form field " + name + " with value " + Streams.asString(stream) + " detected.");
                } else {
                    System.out.println("File field " + name + " with file name " + item.getName() + " detected.");
                    // Process the input stream
                    //...
                }
            }

        } catch (FileUploadException ex) {
              Logger.getLogger(ResourceUploadServlet.class.getName()).log(Level.SEVERE, null, ex);

        }
    }

jsp页面如下:

 <form action="AServlet" method="POST"
              enctype="multipart/form-data">
                            <input type="file" name="Content" />
                            Description : <input  type="text" name="Description" />
                        <input type="submit" value="Submit" />

        </form>

最好,

推荐答案

在我的 web.xml 文件中.有一个过滤器

In my web.xml file. There was a filter

    <filter>
        <filter-name>resourceUploadServlet</filter-name>
        <filter-class>org.mortbay.servlet.MultiPartFilter</filter-class>
        <init-param>
            <param-name>maxSize</param-name>
            <param-value>2147483648</param-value>
        </init-param>
    </filter>

当我移除过滤器时,问题就解决了...

When i remove the filter the problem is solved...

这篇关于Apache 公共文件上传 FileItemIterator hasNext() 返回 false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆