Forms 我有jsp oage,它可以同时上传表单数据和文件。但我得到了java.io.FileNotFoundException:当没有文件上传时

Forms 我有jsp oage,它可以同时上传表单数据和文件。但我得到了java.io.FileNotFoundException:当没有文件上传时,forms,servlets,file-upload,ejb-3.0,filenotfoundexception,Forms,Servlets,File Upload,Ejb 3.0,Filenotfoundexception,这是我的代码。当没有要上传的文件时,我得到了java.io.FileNotFoundException。如果文件是使用表单数据上传的,则工作正常。我的代码有什么问题 当没有上传文件时,我应该如何处理?有人知道如何解决这个问题吗? boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { System.out.println("multipart2");

这是我的代码。当没有要上传的文件时,我得到了java.io.FileNotFoundException。如果文件是使用表单数据上传的,则工作正常。我的代码有什么问题

当没有上传文件时,我应该如何处理?有人知道如何解决这个问题吗?
boolean isMultipart = ServletFileUpload.isMultipartContent(request);

if (isMultipart) {

        System.out.println("multipart2");
        // Create a factory for disk-based file items 
        FileItemFactory factory = new DiskFileItemFactory();
        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);
        try {
            // Parse the request
            List /* FileItem */ items = upload.parseRequest(request);
            Iterator iterator = items.iterator();

            while (iterator.hasNext()) {
                FileItem item = (FileItem) iterator.next();

           if (item.isFormField()) //your code for getting form fields

                {
                    if (item.getFieldName().equals("btn")) {

                        if (item.getString().equals("Submit")) {
                           String name = item.getFieldName();
                           String value = item.getString();
                            System.out.println("test2" + name + value);

                        }
                        if (item.getString().equals("Save as Draft")) {
                            System.out.println("hii hii2");
                            String name = item.getFieldName();
                            String value = item.getString();
                        } 
                   }
          } if (!item.isFormField()) {
                    String fileName = item.getName();
                    System.out.println("File Upload Named :  " + fileName);
                    String root = getServletContext().getRealPath("/");
                    File path = new File(root + "/uploads");
                    if (!path.exists()) {
                        boolean status = path.mkdirs();
                    }
                    File uploadedFile = new File(path + "/" + fileName);
                    // System.out.println(uploadedFile.getAbsolutePath());
                    item.write(uploadedFile);
                }
            }
        } catch (FileUploadException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    response.sendRedirect("/EventCalendar-war/pages/user_pages/user_create_event.jsp");
}