我有一个Web应用程序,该应用程序将Multipart文件作为输入,然后根据特定条件处理记录。处理后,它会重定向回首页。
@RequestMapping(method = RequestMethod.POST, value = "/upload")
public String handleDbfUpload(@RequestParam("file") final MultipartFile multipartFile,
@RequestParam("pqr") final String pqr, @RequestParam("lmn") final Long lmn,
@RequestParam("abc") final BigDecimal abc, @RequestParam("xyz") final BigDecimal xyz,
final RedirectAttributes redirectAttributes, final HttpSession session, final HttpServletRequest request)
throws IOException {
if (!multipartFile.isEmpty()) {
try {
final String adUserName = request.getUserPrincipal().getName();
logger.info("Processing the '{}' file", multipartFile.getOriginalFilename());
final ProcessingStatistics processingStats = dbfProcessingService.processDbfFile(multipartFile,
pqr, lmn, abc, xyz, adUserName);
logger.info("Processing in DbfUploadController 11");
session.setAttribute("lmn", lmn);
redirectAttributes.addFlashAttribute("originalFilename", multipartFile.getOriginalFilename());
logger.info("Processing dbf");
} catch (final IOException | RuntimeException ex) {
logger.error("Failed to upload " + multipartFile.getOriginalFilename(), ex);
redirectAttributes.addFlashAttribute("error",
"Failed to upload or process " + multipartFile.getOriginalFilename() + " - " + ex.getMessage());
} catch(Exception e){
logger.error("Exception encountered", e);
}
} else {
redirectAttributes.addFlashAttribute("error",
"Failed to upload " + multipartFile.getOriginalFilename() + " - file was empty.");
}
logger.info("Processing dbf and redirecting now");
return "redirect:/";
}
}
该文件在Chrome中运行正常,但在Firefox中失败。
观察: 在Firefox中,文件成功上传并处理。它会打印日志的最后一行,并且在重定向之前,它会再次开始上传文件。 在第二次自动上传中尝试操作整个控制器时,Firefox在UI上抛出“安全连接失败” 。
但是,它在Chrome浏览器中可以正常运行,并且不会再次上传文件。