我正在研究spring hibernate,我想导入一个excel文件。我想检查扩展名,以便除了 excel 之外没有人可以上传文件,即限制导入具有以下扩展名之一的文件:xls 或 xlsx。我的代码在这里:
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;
}
}