• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

file uploading using Jakarta file upload

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,


I have a JSP containing five ITEMs,

Here is some code of the JSP:

FORM:
<form name="frmPR" method="post" action="/upload/servlet/UploadServlet" id="frmPR" enctype="multipart/form-data">

FILE ITEMS:
<input name="document" id="document" type="file" class="textbox"/> I have five items.


Here is my servlet code:

File repositoryPath=null;
aList uploadedFiles=new ArrayList();
HttpSession session = request.getSession(true);
StringBuffer errors=new StringBuffer();
if (!ServletFileUpload.isMultipartContent(request)){
response.sendError(HttpServletResponse.SC_NO_CONTENT);
}
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
diskFileItemFactory.setSizeThreshold(40960); /* the unit is bytes */
List fileItemsList = null;

repositoryPath = new File(Configurations.getRootFileLocation());
diskFileItemFactory.setRepository(repositoryPath);
servletFileUpload.setSizeMax(Configurations.getMaximumFileSize()); /* the unit is bytes */

try {
fileItemsList = servletFileUpload.parseRequest(request);






When I check the above FileItemList, it returns me the size equal to 0


AM I Missing something:???


A.B
[ April 28, 2007: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Awais,

See the example at http://jakarta.apache.org/commons/fileupload/using.html.

It looks a lot like your code, main difference is that in your code you create a new DiskFileItemFactory() twice, they create it once and then give it to the
ServletFileUpload:

ServletFileUpload upload = new ServletFileUpload(factory);

Hope this helps.

Herman
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Awais, I am having the same problem. Did you manage to find a solution?
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Maximus Decimus Meridius",

Please check your private messages for an important message from me.

Kind regards,
Katrina Owen
JavaRanch Saloon Bartender
 
reply
    Bookmark Topic Watch Topic
  • New Topic