为什么MultipartFormDataRequest不将信息保存在哈希表中?

时间:2018-12-28 00:10:56

标签: java java-ee hashtable multipartform-data

我的JSP中有2个属性(path_Id和path_Proof_Of_Address),在这些属性中,我会在每个属性中发送一个图像。

但是当使用Hashtable中的MultipartFormDataRequest保存它们时,如果保留大小2,而仅在第一个键(file_Id)中保存一个值,则丢弃在键file_Address中发送的图像。

            MultipartFormDataRequest mrequest = null;

                    UploadBean upBean = null;

                    try {

                        mrequest = new MultipartFormDataRequest(request);

                        Hashtable files = null;

                        files = mrequest.getFiles();

                        System.out.println("Size of Hashtable: " + files.size());

                        Set<String> keys = files.keySet();

                        //Obtaining iterator over set entries
                        Iterator<String> itr = keys.iterator();

                        //Displaying Key and value pairs
                        while (itr.hasNext()) { 
                        // Getting Key
                        String str = itr.next();

                        /* public V get(Object key): Returns the value to which 
                            * the specified key is mapped, or null if this map 
                            * contains no mapping for the key.
                            */
                        System.out.println("Key: "+str+" & Value: "+files.get(str));
                        } 

                        if ((files != null) && (!files.isEmpty())) {

                            UploadFile file_Id = null;

                            if ((UploadFile) files.get("path_Id") != null) {
                                file_Id = (UploadFile) files.get("path_Id");
                            }

                            upBean = new UploadBean();
                            upBean.setFolderstore(path_Id);

                            System.out.println("file_Id: " + /*file_Id.getContentType() + */file_Id.getFileName()/* + file_Id.getFileSize() + file_Id.getClass() + file_Id.getData() + file_Id.getInpuStream()*/);

                            upBean.store(mrequest, "path_Id");

                            if (file_Id.getFileName() != null) {

                                // We get the name of the loaded file
                                name_Image_Id = file_Id.getFileName();

                                // Obtain the extension
                                String extension_Id = FilenameUtils.getExtension(path_Id + name_Image_Id);

                                // We get the path and the original name
                                File f1 = new File(path_Id + name_Image_Id);

                                // We set the name with our nomenclature
                                File f2 = new File(path_Id + "Id_" + email + "." + extension_Id);

                                // We delete the file if already exist
                                f2.delete();

                                // We rename the name with our nomenclature
                                f1.renameTo(f2);

                                // We set the value the name with our nomenclature
                                path_Id = path_Id + name_Image_Id;

                            } else {

                                // if they do not send us any Id, we initialize the path
                                path_Id = null;

                            }

                            UploadFile file_Address = null;

                            if ((UploadFile) files.get("path_Proof_Of_Address") != null) {
                                file_Address = (UploadFile) files.get("path_Proof_Of_Address");
                            }

                            upBean = new UploadBean();
                            upBean.setFolderstore(path_Proof_Of_Address);

                            System.out.println("file_Address: " + /*file_Id.getContentType() + */file_Address.getFileName()/* + file_Id.getFileSize() + file_Id.getClass() + file_Id.getData() + file_Id.getInpuStream()*/);

                            upBean.store(mrequest, "path_Proof_Of_Address");

                            if (file_Address.getFileName() != null) {

                                // We get the name of the loaded file
                                name_Image_Proof_Of_Address = file_Address.getFileName();

                                System.out.println("1");

                                // Obtain the extension
                                String extension_Address = FilenameUtils.getExtension(path_Proof_Of_Address + name_Image_Proof_Of_Address);

                                System.out.println("2");
                                System.out.println(path_Proof_Of_Address);
                                System.out.println(name_Image_Proof_Of_Address);
                                System.out.println(extension_Address);

                                // We get the path and the original name
                                File f1 = new File(path_Proof_Of_Address + name_Image_Proof_Of_Address);

                                // We set the name with our nomenclature
                                File f2 = new File(path_Proof_Of_Address + "Address_" + email + "." + extension_Address);

                                // We delete the file if already exist
                                f2.delete();

                                // We rename the name with our nomenclature
                                f1.renameTo(f2);

                                // We set the value the name with our nomenclature
                                path_Proof_Of_Address = path_Proof_Of_Address + name_Image_Proof_Of_Address;

                            } else {

                                // if they do not send us any Id, we initialize the path
                                path_Proof_Of_Address = null;

                            }

                        } else {

                            System.out.println("The customer do not sent us any file");

                        }
                    } catch (UploadException exc) {
                        System.out.println(exc.getMessage());
                    }

哈希表的大小: 2

密钥: path_Proof_Of_Address和值:javazoom.upload.parsing.CosUploadFile@2eda20da

密钥:路径ID和值:javazoom.upload.parsing.CosUploadFile@1ec42012

file_Id: BGW.jpg

文件地址:

0 个答案:

没有答案