1. 파일 다운로드
2. 댓글기능
3. 에이작스리스트 무한휠에서 네비바 형식으로 변경 (부트스트랩 버튼 그룹)
4. 보드테이블에 아이피주소 넣기
5. 비회원 댓글은 아이피번호 노출되도록?
6. '수정하기'는 '작성하기' 개선 후에 다시 만들기
fileDTO 대신 멀티파트파일로 받기
file.transferTo
FileService 생성
# 부분에 다운로드 기능
클릭시 동작하는
파일컨트롤러 만들기
// 클릭시 파일 다운로드
@RequestMapping("downLoadFile")
public void downLoadFile(int seq, HttpServletResponse resp) throws Exception {
FileDTO fdto = bservice.getFileBySeq(seq);
String filePath = session.getServletContext().getRealPath("upload/"+fdto.getUploader_id());
System.out.println("filePath : "+filePath);
File target = new File(filePath+"/"+fdto.getStored_file_name());
try(DataInputStream dis = new DataInputStream(new FileInputStream(target));
ServletOutputStream sos = resp.getOutputStream();){
String fileName = new String(fdto.getOriginal_file_name().getBytes("utf8"),"iso-8859-1");
resp.reset();
resp.setContentType("application/octet-stream");
resp.setHeader("Content-disposition", "attachment;filename="+fileName+";");
byte[] fileContents = new byte[(int)target.length()];
dis.readFully(fileContents);
sos.write(fileContents);
sos.flush();
}
}
링크를 클릭하면
일단은 받을 값을 보여주도록하기
일단은 리다이렉트 /
하드디스크 파일에 '빨대' 연결
첨부파일 보내기
// 클릭시 파일 다운로드
@RequestMapping("downLoadFile")
public void downLoadFile(int seq, HttpServletResponse resp) throws Exception {
FileDTO fdto = bservice.getFileBySeq(seq);
String filePath = session.getServletContext().getRealPath("upload/"+fdto.getUploader_id());
System.out.println("filePath : "+filePath);
File target = new File(filePath+"/"+fdto.getStored_file_name());
try(DataInputStream dis = new DataInputStream(new FileInputStream(target));
ServletOutputStream sos = resp.getOutputStream();){
String fileName = new String(fdto.getOriginal_file_name().getBytes("utf8"),"iso-8859-1");
resp.reset();
resp.setContentType("application/octet-stream");
resp.setHeader("Content-disposition", "attachment;filename="+fileName+";");
byte[] fileContents = new byte[(int)target.length()];
dis.readFully(fileContents);
sos.write(fileContents);
sos.flush();
}
}
BoardProject(0608 강사님 코드).zip
0.19MB
파일 이름이 한글
크롬 인코딩 방식으로 인코딩 해서 보내주기
'디지털 컨버전스 > Spring' 카테고리의 다른 글
[Spring Framework] 정리 (0) | 2020.06.08 |
---|---|
[Spring Framework] 댓글 (0) | 2020.06.08 |
[Spring Framwork] 파일 업로드 개수 (0) | 2020.06.05 |
[Spring Framework] 파일업로드 (0) | 2020.06.05 |
[Spring Framework] 트랜젝션 처리 (0) | 2020.06.05 |