Olá, Eu estou tentando enviar um arquivo Excel para o controller da minha aplicação e depois vou fazer a leitura de alguns campos especificos. Contudo eu só recebo
HTTP Status 405 ? Method Not Allowed
Type Status Report Message Request method 'POST' not supported
Description The method received in the request-line is known by the origin server but not supported by the target resource.
OBS:
Estou usando o spring security mas eu ja coloquei o permitAll() para os 2 métodos.
O codigo refente a UploadFileHelper, ExcelFile e ExcelHelper encontrei na internet.
Alguém pode me ajudar??
JSP
<form:form action="manager/fileImport" commandName="excelFile" method="POST" enctype="multipart/form-data">
<div class="input-group">
<input type="file" class="form-control">
<span class="input-group-btn">
<button type="submit" class="btn btn-primary" value="Import">Import Excel</button>
</span>
</div>
</form:form>
@Controller
@RequestMapping(value = "manager/fileImport", method = RequestMethod.POST)
private @ResponseBody String loadExcel(@ModelAttribute("excelFile") ExcelFile excelFile, ModelMap modelMap,
HttpServletRequest request) throws ServletException, IOException {
File file = UploadFileHelper.simpleUpload(excelFile.getFile(), request, true, "src");// till 16:00
System.out.println(file.getAbsolutePath());
return "";
}
UploadFileHelper
public static File simpleUpload(MultipartFile file, HttpServletRequest request, boolean encrypt_file_name, String Upload_folder)
{
String filename = null;
File serverFile=null;
try{
if(!file.isEmpty())
{
String applicationPath=request.getServletContext().getRealPath("");
if(encrypt_file_name){
String currentFileName = file.getOriginalFilename();
String extention= currentFileName.substring(currentFileName.lastIndexOf("."), currentFileName.length());
Long nameRadom = Calendar.getInstance().getTimeInMillis();
String newfilename= nameRadom + extention;
filename=newfilename;
}else
filename=file.getOriginalFilename();
byte[] bytes=file.getBytes();
String rootPath=applicationPath;
File dir=new File(rootPath + File.separator + Upload_folder);
if(!dir.exists())
dir.mkdirs();
serverFile=new File(dir.getAbsolutePath() + File.separator + filename);
BufferedOutputStream stream=new BufferedOutputStream(new FileOutputStream(serverFile));
stream.write(bytes);
stream.close();
return serverFile;
}
else {
serverFile=null;
}
}
catch (Exception e) {
// TODO: handle exception
serverFile=null;
}
return serverFile;
}