Files
distribution_erp/WebContent/viewImage.jsp
T
chpark 3e135041ac Initial commit: ILSHIN PLM 프로젝트 소스 코드
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 17:49:38 +09:00

83 lines
2.6 KiB
Plaintext
Executable File

<%@ page import="java.io.*, java.util.*" %>
<%@ page import="java.net.URLEncoder"%>
<%!
public void viewImage(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{
HttpSession session = req.getSession(false);
System.out.println("viewImage()..");
String realFileName = req.getParameter("realFileName");
String savedFileName = req.getParameter("savedFileName");
String attDir = req.getParameter("attDir");
System.out.println("=== viewImage DEBUG ===");
System.out.println("attDir: " + attDir);
System.out.println("savedFileName: " + savedFileName);
// Windows 경로 구분자(\)를 Unix 경로 구분자(/)로 변환
// DB에는 \로 저장되어 있지만, Linux 환경에서는 /로 읽어야 함
if(attDir != null){
attDir = attDir.replace("\\", "/");
}
FileInputStream fis = null;
File imageFile = null;
//헤더 컨텐츠 타입 설정
res.reset();
res.setContentType("image/jpeg");
realFileName = new String(realFileName.getBytes("EUC-KR"), "ISO-8859-1");
ServletOutputStream out = res.getOutputStream();
try{
// 먼저 기본 경로에서 파일 찾기
imageFile = new File(attDir, savedFileName);
// 파일이 없으면 /data_storage 하위 디렉토리에서 검색
if(!imageFile.exists()){
System.out.println("File not found at: " + imageFile.getAbsolutePath());
System.out.println("Searching in subdirectories...");
File dataStorageDir = new File("/data_storage");
if(dataStorageDir.exists() && dataStorageDir.isDirectory()){
File[] subDirs = dataStorageDir.listFiles(File::isDirectory);
if(subDirs != null){
for(File subDir : subDirs){
File potentialFile = new File(subDir, savedFileName);
if(potentialFile.exists()){
imageFile = potentialFile;
System.out.println("Found file at: " + imageFile.getAbsolutePath());
break;
}
}
}
}
}
//파일 센딩
fis = new FileInputStream(imageFile);
byte[] buf = new byte[4*1024];
int bytesRead;
while((bytesRead = fis.read(buf)) != -1){
out.write(buf, 0, bytesRead);
}
}catch(FileNotFoundException e){
System.out.println("FileNotFoundException: " + e.getMessage());
System.out.println("Final imageFile path: " + (imageFile != null ? imageFile.getAbsolutePath() : "null"));
out.println("File Not Found");
}catch(IOException e){
out.println("Problem sending file : "+e.getMessage());
}finally{
if(fis != null){
fis.close();
}
}
}
%>
<%
System.out.println("viewImage.jsp");
out.clear();
out = pageContext.pushBody();
viewImage(request,response);
%>