Take the 2-minute tour ×


request -> JakartaMutltiPartRequest -> files attribute

Here is java code that reads the file

public InputStream parseRequestStreamWithApache(HttpServletRequest request)
  throws FileUploadException, IOException {
  InputStream is = null;
  FileItemFactory factory = new DiskFileItemFactory();
  ServletFileUpload upload = new ServletFileUpload(factory);
  List items = upload.parseRequest(request);
  // here the item size is 0 ,i am not sure why i am not getting my file upload in browser with type="file"
  // but If inspect request in debugger i can see my file realted info in request--->JakartaMutltiPartRequest----->files attribute
  Iterator iter = items.iterator();
  while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();

    if (!item.isFormField()) {
      is = item.getInputStream();

  return is;


Here is JSP part:

<form NAME="form1" action="customer/customerManager!parseRequestStreamWithApache.action" ENCTYPE="multipart/form-data"   method="post" >
     <TABLE >
              <th>Upload File</th>
                   <input name="fileUploadAttr" id="filePath"  type="file" value="">
                  <td > 
                 <Input type="submit" value ="uploadFile"/>
share|improve this question
post your jsp here –  Roman C Oct 24 '12 at 12:12
What is your HTML form code? –  Adam Dyga Oct 24 '12 at 12:12
Posted the jsp/html code too –  M Sach Oct 24 '12 at 12:15
Uploading to struts 2 action? –  Roman C Oct 25 '12 at 11:39

4 Answers 4

up vote 6 down vote accepted

As I said in a comment to the same question, you posted earlier, this is most likely because you have parsed the request already before. The files are part of the request body and you can parse it only one time.


I usually do use commons-upload in that way:

if (ServletFileUpload.isMultipartContent(request)) {
    ServletFileUpload fileUpload = new ServletFileUpload();
    FileItemIterator items = fileUpload.getItemIterator(request);
    while (items.hasNext()) {
    FileItemStream item = fileItems.next();
    if (!item.isFormField()) {
        is = item.openStream();
share|improve this answer
But i did not the parse the request earlier –  M Sach Oct 24 '12 at 12:19
Can you show the rest of your servlet code that does anything with your HttpServletRequest before parseRequestStreamWithApache() is called? –  Udo Klimaschewski Oct 24 '12 at 12:31
I placed the code in very first filter of my webapp, still the same result.So looks like that is not the issue –  M Sach Oct 24 '12 at 12:54
I updated my answer with some code that does it a bit different, maybe you can give it a try? Allways worked for me. –  Udo Klimaschewski Oct 24 '12 at 13:25
Thanks Udo. You was right. looks like struts2 fileupload plugin is already reading in between. –  M Sach Oct 26 '12 at 10:57

You should check for multipart content

boolean isMultipart = ServletFileUpload.isMultipartContent(request);

if (isMultipart) {
    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);

    try {
        List items = upload.parseRequest(request);
        Iterator iterator = items.iterator();
        while (iterator.hasNext()) {
            FileItem item = (FileItem) iterator.next();
            if (!item.isFormField()) {
                String fileName = item.getName();

                String root = getServletContext().getRealPath("/");
                File path = new File(root + "/fileuploads");
                if (!path.exists()) {
                    boolean status = path.mkdirs();

                File uploadedFile = new File(path + "/" + fileName);
    } catch (Exception e) {
share|improve this answer
isMultipart content evalues to true –  M Sach Oct 24 '12 at 12:47
@MSach it seems that action url have collisions with struts filter. If you are using struts why don't you use its fileupload feature? Post web.xml and remove everything except servlet configuration. –  Roman C Oct 24 '12 at 16:51

How big are the files you are uploading? You might be over the default threshold. I think the default is 10K

share|improve this answer
The threshold sets the limit up what size the data will be kept in memory, if the threshold (10K default is correct) is passed, the data will be stored on disk. In java.io.tempdir by default. –  Udo Klimaschewski Oct 24 '12 at 12:26

If you are using weblogic 12 then check whether the patch_wls1211 is insatlled or not. I was having the same issue and it resolved after applying patch_wls1211.

share|improve this answer

Your Answer


