Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make file uploader which can upload docx in jsp

 
Pritam Chatterjee
Ranch Hand
Posts: 38
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to make file uploader which can upload docx in jsp
 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using any framework in your project?
 
Pritam Chatterjee
Ranch Hand
Posts: 38
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
na any framework..i'm doing it in netbeans 7 using glasfish
 
Tim Moores
Bartender
Posts: 2895
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apache Commons FileUpload is an excellent library to handle file uploads at the server side. It doesn't care about the file type being uploaded. Is that what you're asking about?
 
thor aniket
Ranch Hand
Posts: 40
Hibernate jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does Apache commons lib require any FTP server of our own to upload the files?? or it's having its own method of uploading??
I wanted the same functionality but couldn't find any sample.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you upload a file to a webserver, it doesn't require an FTP client or server. HTTP has its own protocols.

To make them work, you have to define a form with the multipart-mime attribute, which tells the server that there will be several different types of data coming in and that they will be encoded using the Multipart Internet Mail Extensions standard. You also have to include a file upload HTML control in the form. This control will present the client-side file selection dialog and define the characteristics of the uploaded file.

When the user has selected a file and clicked the "submit" button for that form, the HTTP client will prepare and transmit an HTTP data stream consisting of headers, form control values, and a MIME-encoded copy of the data read from the selected file. On the receiving side, the webapp will accept all of that and the file data will generally end up stored as a temporary file where it can be retrieved as an inputstream for the application logic to use however it wants. You will need something like the apache commons fileupload facility to help you unless you're really determined to re-invent the whole process yourself.

Note that what's actually uploaded isn't literally a "file", it's the data that came from a file, and the webapp never has to treat it as a file if it just wants to scan the incoming data and do something with it.

However, since it's a very common thing to take the uploaded data and put it into a server-side file (or a BLOB in a database), you can use plain old Java code to create a File and copy the incoming data into that file. What you name the server-side file and where you put it are up to you, except that you should never put that file in a directory that's part of a WAR or the webapp server.
 
thor aniket
Ranch Hand
Posts: 40
Hibernate jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Tim, I got what you've said. I even got a sample program of what you said just now using just HTTP with the form having Multipart MIME. First, I didn't know the workflow of it, but as you have explained it clearly, I got the whole procedure of file uploading with HTTP using Apache commons fileupload . Thank you so much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic