Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using enctype =multipart

 
pramod talekar
Ranch Hand
Posts: 328
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

I've a jsp page where the user needs to either upload a text file or enter some data in a text field and submit.
If I just keep the file upload option and use the Apache Commons upload api and "enctype=multipart/form-data" then everything works fine.
However, if the text box is also made available and enctype is removed in the jsp, then
this line doesn't work and the method containing this code exits immediately.
Now, if I keep enctype as well, then if the file is uploaded and the text field is kept blank, then I get Null Pointer exception for reading the request parameter of textfield.

Could you please tell me if both text field and file uploading can be used with enctype set to multipart/form-data.

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pramod talekar wrote:Hi Bear

Though I'm flattered, it's rather bad form to address a specific person in a forum post. What if someone else has the answer and sees this before I do? Do you not want to hear from that person?

I any case, when using an enctype other than the default, the getParameter() and related methods of the request interface do not work. The commons package for uploading have methods to fetch the parameter values and that's what you should be using.
 
pramod talekar
Ranch Hand
Posts: 328
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

I saw the last response given by you some time back, so guessed you were available.

Right now, I've removed the text field for now, it appears that the request is submitting two variables of type List.
in this

If I iterate over this List and print ouput of getFieldName(), it prints even the Submit button name, which means the button used to submit the form was also sent over in the request.
Please correct me if I'm wrong here.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, all form elements will take part in the submission as usual.
 
pramod talekar
Ranch Hand
Posts: 328
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My jsp is having enctype ="multipart/form-data" value and I'm able to upload a file and read it using Apache commons upload api.
But the jsp also contains a text field to enter some data and either the text field or the file needs to be uploaded at a time.

this is the jsp code:


Now, if I only enter in the text field, then



here, when only text field is keyed in, then

what can I write here to retrieve the eventId mentioned on the jsp?
I tried out few operations on FileItem item but no use.
Please advise.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pramod talekar wrote:I tried out few operations on FileItem item but no use.

Keeping what you tried a secret isn't going to be of any help/ What did you do and how did it not work?

And, as this is now about using the Commons Upload API, it's been moved to a more appropriate forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic