Почему MultipartFormDataRequest не сохраняет информацию в Hashtable? - PullRequest
0 голосов
/ 28 декабря 2018

У меня есть 2 атрибута в моем JSP (path_Id & path_Proof_Of_Address), в них я отправляю изображение в каждом атрибуте.

Но при сохранении их с MultipartFormDataRequest в Hashtable, если вы резервируете размер 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());
                    }

Размер Hashtable: 2

Ключ: path_Proof_Of_Address & Value: javazoom.upload.parsing.CosUploadFile@2eda20da

Ключ: path_Id & Значение: javazoom.upload.parsing.CosUploadFile1016

file_Id: BGW.jpg

file_Address: null

...