File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how to upload file along with HTML form data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to upload file along with HTML form data" Watch "how to upload file along with HTML form data" New topic
Author

how to upload file along with HTML form data

pranith nani
Greenhorn

Joined: Jul 26, 2007
Posts: 7
hi,
when i try to upload a file along with html form data,am using enctype="multipart/form-data" in the form tag to upload a file.but when i use enctype="multipart/form-data" am unable to get form data.its showing null values.when i remove the enctype attribute from form tag its working fine,but unable to upload the file.pls tell me what might be the reason...am geting frustated with this prob...pls help me out....

lots of thanks in advance
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
when i remove the enctype attribute from form tag its working fine,but unable to upload the file


Could you please explain as what exactly is failing.

" Its working fine ,but unable to upload a file" - then how is that working fine ?

This might be useful.
[ July 26, 2007: Message edited by: Rahul Bhattacharjee ]

Rahul Bhattacharjee
LinkedIn - Blog
pranith nani
Greenhorn

Joined: Jul 26, 2007
Posts: 7
i have html form values(ex:username,password,location,ph no,etc.,)and also browse file option.when i put the attribute enctype="multipart/form-data" in the form tag,the form values(ex:username,password,location,ph no,etc.,)are going as null to database but the file is getting uploaded.when i remove the "enctype" attribute from the form tag all the form values are getting stored in database but the file is not getting uploaded.how can i resolve this......

thanks for your interest
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
What are you doing on the server side to read the multipart data coming from the browser ?
[ July 26, 2007: Message edited by: Rahul Bhattacharjee ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Multipart posts work differently from regular form posts.
You can not use request.getParameter to retrieve form parameters.

You will need to read the documentation for the upload libraries you're using to find out how to get them.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
pranith nani
Greenhorn

Joined: Jul 26, 2007
Posts: 7
thanks a lot for your reply.can i have the documentation or a link regarding that so that it will be easy for me.am trying for this since 10 days but of no use..
pranith nani
Greenhorn

Joined: Jul 26, 2007
Posts: 7
am preparing a page similar to naukri.so i need to get the user details(like email,phno,skillset,etc.,)along with his resume.i am storing the files in a specified path and the form values in the database...this is the theme of my work
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I have already sent you the link in my first post.
You might also have a look in Javaranch's FAQ.

http://faq.javaranch.com/view?FileUpload
pranith nani
Greenhorn

Joined: Jul 26, 2007
Posts: 7
am using JDeveloper.how can i import org.apache.*;is that the only process?
pranith nani
Greenhorn

Joined: Jul 26, 2007
Posts: 7
if you dont mind can i have an example with a browse option to upload a file and a textbox to store the data in the database...pls,help me out...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You have to pick an upload library and read the documentation that comes with it. Personally, I use Apache Jakarta Common's 'fileupload' which has simple examples in its documentation.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Also, the article linked to by Rahul Bhattacharjee in his earlier post has some very nice code samples. Did you read it?
pranith nani
Greenhorn

Joined: Jul 26, 2007
Posts: 7
i dont have tomcat installed.can i have any other way to escape the prob???
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What container are you using?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
Originally posted by pranith nani:
i dont have tomcat installed.


It doesn't have to be Tomcat - just use the servlet container you have. File upload is an HTTP feature - it works the same on all containers.


Ping & DNS - my free Android networking tools app
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to upload file along with HTML form data
 
Similar Threads
HTML Form Upload produces junk characters
Action form is not populated while using html:form enctype="multipart/form-data"
HTTP 500 Servelet error while uploading
How to get the request parameters while the enctype is multipart/form-data
problem with enctype="multipart/form-data"