In Servlet, when a request is made to post a file to the server, the enctype attribute of the Form in html will be specified as "multipart/form-data" and the input we give will be as type "file". And we will be dealing the input as Part(the propertiy of a request Object). In my one of code i upload a file through form to FTP server. But it shows null pointer exception. Below is the code for form and the servlet response(i have mentioned where the null pointer exception is thrown) in the Post method.
<form method="POST" action="upload" enctype="multipart/form-data">
<p>Browse for a file to upload: </p>
<input type="file" name="file" id="file">
<br /><br />
<input type="submit" value="Upload It Now">
Part filePart = request.getPart("file"); //returns null
String fileName = getFileName(filePart); //this is another method which is given below
It would also help if you explained the relationship between the servlet you're asking about and the FTP server to which some upload is somehow being done.
posted 7 years ago
Thanks for your reply.
Yes, I could tell you the relationship between servlet and the FTP server. The FTP server to which i want to upload is something that i have maintaining in my local machine. That is i have created FTP server locally using IIS. Now the FTP server folder is said to be inside the "E:\Inetpub\ftproot". Below is the code that contain the implementation inside the doPost method of a servlet to upload a FILE to FTP server.