• Add a Comment
  • Edit
  • More Actions v
  • Quarantine this Entry

Comments (9)

1 localhost commented Permalink

DiskFileUpload has a known MEMORY LEAK (and is now deprecated). This leak was particularly funky in that it leak into the NATIVE space (not the Java heap.)

 
You should use the newer ServletFileUpload in your example.
 
See: http://jakarta.apache.org/commons/fileupload/apidocs/index.html

2 localhost commented Trackback

Thanks for pointing that out Stephen. I have updated the example code to use ServletFileUpload.

3 localhost commented Permalink

Hi,I have 2 question.I use commons-fileupload-1.2.

 
first,pls update your code:"<%@ page import="java.sql.*,java.util.*,java.io.* %>" =>"<%@ page import="java.sql.*,java.util.*,java.io.*" %>"u lose a quotation mark here;
 
"int docsize = 0;" => "long docsize = 0;"in v1.2 it return long.
 
 
 
below are my question:1."docstream = (FileInputStream) fi.getInputStream();"when i browse it in IE,it threw exception:java.lang.IllegalStateException....java.lang.ClassCastException: java.io.ByteArrayInputStream...Why?
 
2.Since i can`t run it,i change your code to below:
 
tring docfilename = "";long docsize = 0;String contentsdf = "";
 
DiskFileItemFactory factory = new DiskFileItemFactory();ServletFileUpload fu = new ServletFileUpload(factory);List fileItems = fu.parseRequest(request);Iterator itr = fileItems.iterator();
 
fu.setSizeMax(1000000);int i =0;while (itr.hasNext()) { out.println("NO." + i + "
"); i++; FileItem fi = (FileItem) itr.next(); if (!fi.isFormField()) { docfilename = fi.getName(); docsize = fi.getSize(); contentsdf = fi.getString(); } if (docsize > 0) { out.println("FILENAME:" + docfilename + "
"); out.println("FILESIZE:" + docsize + "
"); out.println("FILECONTENT:" + contentsdf + "
"); }}
 
it can work,but a new problem:it repeat the last file.I mean:i write more "
" in the html file,of course it has deferent name like "docfile1","docfile2"...but i upload one file,it show me two;i upload two ,it show me three.And it always repeat the last file i upload.Why?
 
in any case,Thank you very much,your code are the only one which i can run under commons-fileupload-1.2.THANKS a lot!

4 localhost commented Trackback

Kane, thanks for the feedback. I have corrected the missing quote and changed docsize to long. I will test this in IE and comment again... Guy

5 localhost commented Permalink

these are my new code.it can work,but i still can not understand why parseRequest() return one more file.[code]upload.jsp********<%@ page language="java" pageEncoding="UTF-8"%>

upload2.jsp********<%@ page language="java" pageEncoding="UTF-8"%><%@ page import="java.util.*"%><%@ page import="org.apache.commons.fileupload.*"%><%@ page import="org.apache.commons.fileupload.servlet.*"%><%@ page import="org.apache.commons.fileupload.disk.*"%>

6 localhost commented Trackback

I find the key.fileItems.size(),it return the whole num of input in the first file,like upload.jsp in my code.just "

" =>
 
it done.
 
****************upload1.jsp[code]<%@ page language="java" pageEncoding="UTF-8"%>
[/code]*************************upload2.jsp[code]<%@ page language="java" pageEncoding="UTF-8"%><%@ page import="java.util.*"%><%@ page import="org.apache.commons.fileupload.*"%><%@ page import="org.apache.commons.fileupload.servlet.*"%><%@ page import="org.apache.commons.fileupload.disk.*"%>

7 localhost commented Trackback

Kane, thanks for providing a complete example - I have updated the article to refer to your comments.

8 localhost commented Permalink

hi!

 
I'm trying to test your example. If the picture is smaller than 10K, fails with:
 
ERROR StandardWrapperValve(invoke:278) - Servlet.service() for servlet PicAction threw exceptionjava.lang.ClassCastException: java.io.ByteArrayInputStreamat com.PicAction.doPost(PicAction.java:95)
 
 
 
95: docstream = (FileInputStream) fi.getInputStream();
 
Any ideas how to fix this?
 

9 localhost commented Permalink

Desrcibe the difference between asp & jsp. Which one is better to create online shopping mall.

Add a Comment Add a Comment