我的页面代码:
<body>
<form action="<%=request.getContextPath()%>/business/com.ai.offering.UploadFile?action=uploadFile" method="post" enctype="multipart/form-data" name="form1">
<input type="file" id = "file">
<input type="submit" value="Up">
</form>
<input type="button" value="Down">
</body>
我的servlet代码:
    try {
            if(this.uploadPath.equals(""))
            {
              this.isWriteToDataBase = true;
            }
            else 
            {
              this.isWriteToDisk = true;
            }
            boolean isMultipart = FileUpload.isMultipartContent(request);
            if(isMultipart)
            {
              System.out.println("mmmmm");
            }
            
            // Create a factory for disk-based file items
            FileItemFactory factory = new DiskFileItemFactory();
            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload(factory);
            // Parse the request
            List items = upload.parseRequest(request);
            Iterator i = items.iterator();
            while(i.hasNext()) {
             .......
            }
    }

解决方案 »

  1.   

    http://jakarta.apache.org/site/downloads/downloads_commons.html文件:Download commons-io-1.2.zip(与”commons-fileupload-1.1.jar”放一起)
      

  2.   

    别人的方法借用一下:)
    Map parameters = new HashMap(); 
    if (fi.isFormField()==true){// 如果是请求参数,则保存到HashMap中
                String name = fi.getFieldName();
                String value = fi.getString();
                parameters.put(name, value);
    }
    /* 处理完成后,此时所有请求参数存放在 parameters 变量中
       可以通过 (String)parameters.get("xxx") 来读取参数
    */