I am working on spring hibernate and I want to import an excel file. I want to make a check on extensions so that no one can upload a file other than excel i.e. restrict the import to files with one of these extensions: xls or xlsx. My code is here:
public class ImportCandidatesFormController extends BNUAbstractFormController {
private ImportCandidatesBL importCandidatesBL;
private ExcelReader reader;
@Override
protected ModelAndView processFormSubmission(HttpServletRequest request,
HttpServletResponse response, Object command, BindException arg3)
throws Exception {
FileUploadVO vo = (FileUploadVO) command;
MultipartFile file = vo.getFile();
System.out.println("File Uploaded: " + file.getOriginalFilename());
boolean isSuccessful = importCandidatesBL.importAndSaveCandidates(
file.getInputStream(),
SessionUtil.getCurrentUser(request.getSession()));
return new ModelAndView(new RedirectView("importCandidates.do?s=1"));
}
public ImportCandidatesBL getImportCandidatesBL() {
return importCandidatesBL;
}
public void setImportCandidatesBL(ImportCandidatesBL importCandidatesBL) {
this.importCandidatesBL = importCandidatesBL;
}
}