This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
An IDE is no substitute for an Intelligent Developer.
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.