• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

uploading files, using more than one element in the form

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,

I am using Jakarta Commons for uplaoding file. the files are uploaded correctly, the problem is if i have in tha same form for uploading a file other form elemenrs like a text field, whenever i use the requesti.getParameter() it returns null althoug this text field is inside hte same form as the file input?? so how to include other inpt fields with the file??

Thanks
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getParameter() will not work with multi-part forms. You'll need to check the API for the upload package for how it supports obtaining the parameters.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maha,

If you are using apache commons, the parseRequest(..) method gives you the list of FileItem's, the form fields will be part of that list.

You can use isFormField() method on the FileItem (while enumerating the list) to verify if its a form field, and you can get the value of the form field using getString() and name of the field using getFieldName() methods on FileItem.

Regards,
Srivatsa Katta
 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srivatsa,

Thanks a lot for your reply, It was very helpful.

I was wondering if I want the content of the file as byte[] what shall I do, I know I will use the fileItem.getInputStream() but I do not know how to use it any help!!

Thanks a lot
 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I found that I can use to get the byte array for the file, i can then add it to a session and use it from the servlet to write the file to the server

Thanks
 
Yup, yup, yup. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic