2013-10-31 6 views
0

나는 봄과 겨울잠을 사용하여 자바 웹 앱 개발을 마쳤다. 내 응용 프로그램에는 다운로드 기능이 있습니다. 이 기능은 Windows 환경에서 잘 실행됩니다. 하지만 서버로 톰캣을 사용하여 linux env에 앱을 배포하고 실행하면이 함수는 0 바이트 파일을 반환합니다. 파일 형식은 Excel (xls)입니다. 그러나 브라우저는 이것을 pdf 파일로 반환합니다. 리눅스에Linux에서 다운로드 파일 경로를 얻는 방법은 무엇입니까?

Download Failed

XLS 파일 경로 : xls

을 여기에 코드입니다 :

다운로드 기능이 실패

@RequestMapping("downloadXlsTemplate") 
public String downloadTemplate(HttpServletRequest request, HttpServletResponse response) { 

    try {   

     String filename = "Template.xls"; 

     File onLinux = new File("/opt/tomcat7/webapps/xls/" + filename); 

     response.setContentType("application/vnd.ms-excel"); 
     response.addHeader("Content-Disposition", "attachment; filename=" + filename); 
     response.setContentLength((int) onLinux.length()); 

     InputStream inputStream = new FileInputStream(onLinux); 

     OutputStream responseOutputStream = response.getOutputStream(); 
     int bytes; 
     while((bytes = inputStream.read()) != -1) { 
      responseOutputStream.write(bytes); 
     } 
     inputStream.close(); 
     responseOutputStream.close(); 

    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return null; 
} 

나는 다양한 방법을 시도했지만 없음 성공했습니다. 는 정말

감사 유누스

답변

0

당신이 직면하고있는 문제는 파일 권한 문제를, 어떤 생각을 주셔서 감사합니다 도움이, 또는 솔루션 것입니다. 이 파일은 'root'가 소유하며 다른 사용자는 tomcat이 실행됩니다.

파일을 tomcat 사용자가 액세스 할 수있는 공유 위치로 이동하십시오. /tmp 위치 또는 다른 공유 위치를 사용해보십시오.

0

권한 문제인 경우 파일에 대한 필수 권한을 제공하는 chmod unix 명령을 사용해보십시오.

예컨대, U + 좋은 방법으로서 RWX

chmod를 상기 (클래스 경로 자원을 사용하는) 상대 경로를 사용하여 파일 대신 절대 경로를 참조하도록 시도 (그래서 독립적 환경).

관련 문제