Here my requirement is to upload the file and to store it in the disk. I have no problem in storing it in disk, but getting the extension of the file. The problem is when I clic
To get the extension of a file from servlet upload, your form enctype should be "multipart/form-data" Example upload form:
On the server-side, the parameter name of the file will correspond to the "name" attribute of the input.
//...other request handling code
Part filePart = request.getPart("file");/*"name" attribute of your input*/
String fileName = filePart.getSubmittedFileName();//full name of file submitted
String[] fileNameSplit = fileName.split(".");//split between name and extension
String extension = fileNameSplit[fileNameSplit.length-1];//get the extension part of the file name