This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
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.
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.
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.