JSP & Servlet

게시글에 따른 폴더 생성하여 저장하기.

Jungsoomin :) 2020. 7. 31. 15:52

File 객체 생성자에 경로를 주면 해당 파일객체가 만들어진다.

 

no는 글 번호이며 이는 가변경로이니 @PathValariable 로 가져다 쓸 수 있을 듯 하다.

 

즉 글 번호 하나마다 폴더를 생성하여 사용하게 된다.

String path = "C:\\tempfiles\\"+no;
			
			File file = new File(path);
			
			if(!file.exists()) {
				file.mkdirs();
			}

jsp 태그에서의 이미지 유무에 따른 사용이다. 데이터베이스에 파일 이름이 존재하면다면 

<context>태그에서 지정한 path 값으로 이미지를 가져오는데, 

 

Path/{number}/{파일명} 이다.

<c:if test="${not empty articleData.content.fileName}">
  		<img width="30%" src="/images/${articleData.content.number}/${articleData.content.fileName}" alt="이미지 깨짐" />
  	</c:if>