This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes using enctype =multipart Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "using enctype =multipart" Watch "using enctype =multipart" New topic
Author

using enctype =multipart

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

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.


Thanks,
Pramod
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

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

Joined: Jan 10, 2002
Posts: 60741
    
  65

Yes, all form elements will take part in the submission as usual.
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

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

Joined: Jan 10, 2002
Posts: 60741
    
  65

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.
 
Don't get me started about those stupid light bulbs.
 
subject: using enctype =multipart
 
Similar Threads
Encoding problem with File Upload
Enumeration is not returning any data
File Upload
Action form is not populated while using html:form enctype="multipart/form-data"
request.getParameter()