Apache commons fileupload FileItemIterator hasNext() returns false

后端 未结 2 1569
再見小時候
再見小時候 2021-01-14 23:10

I\'m using the apache commons fileupload stream api. But the FileItemIterator FileItemIterator iter = upload.getItemIterator(request); returns false in its hasN

相关标签:
2条回答
  • 2021-01-14 23:21

    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...

    0 讨论(0)
  • 2021-01-14 23:26

    A few things that might be worth checking for:

    • Is the doPost() method the same as that of the servlet "AServlet" referred to in the form? This is primarily to ensure that the request has not already been read, in which case parsing of the request into FileItem objects will not happen. A request once parsed, cannot be parsed again by Commons FileUpload; usually the presence of servlets and filters upstream is responsible for this condition.
    • Is the form submit actually working? And does the issue recur with different files? Ideally, the Commons Fileupload component will not return any more items when the End Of File condition has been reached, i.e. there is no more data to read (the number of bytes in content-length header has been read from the body).

    PS: It might be better to use the Logger class to be 'doubly sure' on whether the Form and File field parsing is being done or not.

    0 讨论(0)
提交回复
热议问题