upload.parseRequest(request) returns empty list in commons.fileUpload

自作多情 提交于 2019-12-07 14:44:23

问题


I am using org.apache.commons.fileUpload.FileItem and other related classes for uploading files from local machine to server (Although for the current testing both the machines are same).

I am having .jsp file as UI and servlet to handle the upload. Now when the request reaches statement

List items = upload.parseRequest(request);

it returns empty list. I googled this thing at many places. Most of them specifying the symptons that parserequest() returns empty. But Could not find out the exact solution to avoid this. At one place I could see that Tomcat may have filters that may have parsed The request and thats why at above call to parseRequest returns empty list. But there is no specification how to avoid this.

Is it because of the web server I am using (which is JBOss) ? or has it anything to do with the java version and commons.jar version conflicts ?

I am using

  • jre 1.6
  • jboss-4.0.4.CR2
  • commons-fileupload-1.2.2.jar
  • Eclipse (To create dynamic web project)

Your help would be very much useful.


回答1:


I encountered this same problem with a similar setup in Tomcat. The solution was as simple as placing a name attribute on my input file element.

Before I had <input type="file" /> in my HTML form.

Once I added a name tag i.e. <input type="file" name="aFile" /> my DiskFileUpload object stopped returning an empty list when I called parseRequest(request) from the servlet/JSP.




回答2:


I'm using jboss 5.1 and have no troubles using commons-fileupload libs. Make sure you have the right version of jboss 4.0.4 (jre 1.6) as it may only support jre 1.5. You may want to consider upgrading to the next version if 1.6 is a requirement or change your jre to 1.5.

You should post more of you java and JSP code so we can see how you are posting the request. Good Luck



来源:https://stackoverflow.com/questions/3499385/upload-parserequestrequest-returns-empty-list-in-commons-fileupload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!