Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

using enctype =multipart

 
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • 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.
 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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: 367
Eclipse IDE Opera Java
  • 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
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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: 367
Eclipse IDE Opera Java
  • 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
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!