Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

JS Coding

[Java] 파일 다운로드 (File Download) 본문

Java

[Java] 파일 다운로드 (File Download)

JSKJS 2024. 1. 2. 13:40

프로젝트 내 자료 다운로드 웹페이지 이미지

 

<c:set value="${dataView.atchFileNo}" var="atchFileNo"></c:set>	
			<button type="button" class="btn btn-lg btn-info" 
			onclick="location.href='${pageContext.request.contextPath }/professor/classroom/file/${atchFileNo}'">자료 다운로드</button>
			<table class="table_style02 table_center">

 

View.jsp 를 불러오면서 ATTACHING_FILE 테이블의 PK키를 변수로 button onclick 속성 통한 동기식 요청

 

 

 

Controller 에서 Get 방식으로 

ResponseEntity 타입의 제너릭 <Resource> 로 구성하였으며,

 

ResponseEntity에 대한 설명 -- 

HttpEntity 클래스를 상속받아 구현한 클래스가 RequestEntity, ResponseEntity 클래스이다. ResponseEntity는 사용자의 HttpRequest에 대한 응답 데이터를 포함하는 클래스이다. 따라서 HttpStatus, HttpHeaders, HttpBody를 포함한다. 

 

 

serviceImpl 로직처리 구간에서 해당 파일 정보들을 가져오고 정보를 Resource를 통해 파일 저장된 경로를 지정하여 

파일명을 매개변수로 데이터를 찾고 Header 타입으로 담고 Body를 통해 보낸다.