Why does not the MultipartFormDataRequest save information in the Hashtable?
I have 2 attributes in my JSP (path_Id & path_Proof_Of_Address), in these I send an image in each attribute.
But when saving them with the MultipartFormDataRequest in the Hashtable, if you reserve the size of 2, but only save a value in the first key (file_Id), discarding the image sent in the key 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());
}
Size of Hashtable: 2
Key: path_Proof_Of_Address & Value: javazoom.upload.parsing.CosUploadFile@2eda20da
Key: path_Id & Value: javazoom.upload.parsing.CosUploadFile@1ec42012
file_Id: BGW.jpg
file_Address: null
java java-ee hashtable multipartform-data
add a comment |
I have 2 attributes in my JSP (path_Id & path_Proof_Of_Address), in these I send an image in each attribute.
But when saving them with the MultipartFormDataRequest in the Hashtable, if you reserve the size of 2, but only save a value in the first key (file_Id), discarding the image sent in the key 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());
}
Size of Hashtable: 2
Key: path_Proof_Of_Address & Value: javazoom.upload.parsing.CosUploadFile@2eda20da
Key: path_Id & Value: javazoom.upload.parsing.CosUploadFile@1ec42012
file_Id: BGW.jpg
file_Address: null
java java-ee hashtable multipartform-data
just set breakpoints and see what is happening. It is not clear from the code but since file address is null it means this piece of code is not getting executedif ((UploadFile) files.get("path_Proof_Of_Address") != null) { file_Address = (UploadFile) files.get("path_Proof_Of_Address"); }print thefiles.get("path_Proof_Of_Address")before thisifblock and if it printsnullthen that means somewhere you are manipulating thefileshastable.
– Yug Singh
Dec 28 '18 at 1:51
add a comment |
I have 2 attributes in my JSP (path_Id & path_Proof_Of_Address), in these I send an image in each attribute.
But when saving them with the MultipartFormDataRequest in the Hashtable, if you reserve the size of 2, but only save a value in the first key (file_Id), discarding the image sent in the key 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());
}
Size of Hashtable: 2
Key: path_Proof_Of_Address & Value: javazoom.upload.parsing.CosUploadFile@2eda20da
Key: path_Id & Value: javazoom.upload.parsing.CosUploadFile@1ec42012
file_Id: BGW.jpg
file_Address: null
java java-ee hashtable multipartform-data
I have 2 attributes in my JSP (path_Id & path_Proof_Of_Address), in these I send an image in each attribute.
But when saving them with the MultipartFormDataRequest in the Hashtable, if you reserve the size of 2, but only save a value in the first key (file_Id), discarding the image sent in the key 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());
}
Size of Hashtable: 2
Key: path_Proof_Of_Address & Value: javazoom.upload.parsing.CosUploadFile@2eda20da
Key: path_Id & Value: javazoom.upload.parsing.CosUploadFile@1ec42012
file_Id: BGW.jpg
file_Address: null
java java-ee hashtable multipartform-data
java java-ee hashtable multipartform-data
asked Dec 28 '18 at 0:10
Iván
1
1
just set breakpoints and see what is happening. It is not clear from the code but since file address is null it means this piece of code is not getting executedif ((UploadFile) files.get("path_Proof_Of_Address") != null) { file_Address = (UploadFile) files.get("path_Proof_Of_Address"); }print thefiles.get("path_Proof_Of_Address")before thisifblock and if it printsnullthen that means somewhere you are manipulating thefileshastable.
– Yug Singh
Dec 28 '18 at 1:51
add a comment |
just set breakpoints and see what is happening. It is not clear from the code but since file address is null it means this piece of code is not getting executedif ((UploadFile) files.get("path_Proof_Of_Address") != null) { file_Address = (UploadFile) files.get("path_Proof_Of_Address"); }print thefiles.get("path_Proof_Of_Address")before thisifblock and if it printsnullthen that means somewhere you are manipulating thefileshastable.
– Yug Singh
Dec 28 '18 at 1:51
just set breakpoints and see what is happening. It is not clear from the code but since file address is null it means this piece of code is not getting executed
if ((UploadFile) files.get("path_Proof_Of_Address") != null) { file_Address = (UploadFile) files.get("path_Proof_Of_Address"); } print the files.get("path_Proof_Of_Address") before this if block and if it prints null then that means somewhere you are manipulating the files hastable.– Yug Singh
Dec 28 '18 at 1:51
just set breakpoints and see what is happening. It is not clear from the code but since file address is null it means this piece of code is not getting executed
if ((UploadFile) files.get("path_Proof_Of_Address") != null) { file_Address = (UploadFile) files.get("path_Proof_Of_Address"); } print the files.get("path_Proof_Of_Address") before this if block and if it prints null then that means somewhere you are manipulating the files hastable.– Yug Singh
Dec 28 '18 at 1:51
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53952260%2fwhy-does-not-the-multipartformdatarequest-save-information-in-the-hashtable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53952260%2fwhy-does-not-the-multipartformdatarequest-save-information-in-the-hashtable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
just set breakpoints and see what is happening. It is not clear from the code but since file address is null it means this piece of code is not getting executed
if ((UploadFile) files.get("path_Proof_Of_Address") != null) { file_Address = (UploadFile) files.get("path_Proof_Of_Address"); }print thefiles.get("path_Proof_Of_Address")before thisifblock and if it printsnullthen that means somewhere you are manipulating thefileshastable.– Yug Singh
Dec 28 '18 at 1:51