controller
@RequestMapping(value = { "/downloadFile.do" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST })
public ModelAndView downloadFile(
@RequestParam(value = "path", required = true) String path) {
File file = new File(path);
File downloadFile = new File(path);
return new ModelAndView("fileDownload", "downloadFile", downloadFile);
}
jsp
<html>
<button onclick="downloadFile('${path}')"></button>
<html>
<script type="text/javascript">
function downloadFile(path) {
$('<form>', {
"id": "downloadForm",
"name" : "downloadForm" ,
"method" : "post",
"action": "${pageContext.request.contextPath}/downloadFile.do?path="+path
}).appendTo(document.body).submit();
}
</script>
'Programming > JSP' 카테고리의 다른 글
#jstl ArrayList<ArrayList<hashMap<String, String>>> jstl 출력 (0) | 2021.03.03 |
---|---|
#jsp - chart 종류 (0) | 2021.02.10 |
#JSP - ajax form에 추가 데이터 붙여 보내기 append(), data : 수정 필요 (0) | 2020.08.11 |
댓글