protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
ModelAndView m = new ModelAndView();
response.setContentType("text/plain");
if(!(request instanceof MultipartHttpServletRequest)){
//요청이 해당 request 가 아닐 때
response.sendError(HttpServletResponse.SC_BAD_REQUEST,"잘못된 요청입니다.");
return null;
}
//file 정보
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request;
MultipartFile file = multipartRequest.getFile("file");
String file_name = file.getOriginalFilename();
File file_path = File.createTempFile("file", file_name, path);//파일의 저장될 경로
long size = file.getSize();
FileCopyUtils.copy(file.getInputStream(), new FileOutputStream(file_path));//copy
FileUploadBean bean = (FileUploadBean)command;
bean.setFile(file);
bean.setFile_name(file_name);
bean.setFile_path(file_path);
bean.setSize(size);
boardService.insertFile(bean);
m.setViewName("/fileuploadSuccess.do");
return m;
}
HttpServletResponse response, Object command, BindException errors)
throws Exception {
ModelAndView m = new ModelAndView();
response.setContentType("text/plain");
if(!(request instanceof MultipartHttpServletRequest)){
//요청이 해당 request 가 아닐 때
response.sendError(HttpServletResponse.SC_BAD_REQUEST,"잘못된 요청입니다.");
return null;
}
//file 정보
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request;
MultipartFile file = multipartRequest.getFile("file");
String file_name = file.getOriginalFilename();
File file_path = File.createTempFile("file", file_name, path);//파일의 저장될 경로
long size = file.getSize();
FileCopyUtils.copy(file.getInputStream(), new FileOutputStream(file_path));//copy
FileUploadBean bean = (FileUploadBean)command;
bean.setFile(file);
bean.setFile_name(file_name);
bean.setFile_path(file_path);
bean.setSize(size);
boardService.insertFile(bean);
m.setViewName("/fileuploadSuccess.do");
return m;
}