2017-12-12 26 views
0

다음 JSF 다운로드 방법이 있습니다. 모든 것이 잘 작동합니다. 다운로드 상자가 나타나고 파일이 선택한 디렉토리에 다운로드 된 후 페이지의 커서가 응답 대기중인 것처럼 계속 작동합니다. 그 때문에 나는 페이지의 어떤 요소도 클릭 할 수 없다.JSF 파일 다운로드 - 응답 대기중인 것처럼 커서가 바쁘다

public void download()throwsIOException{ 
    FacesContext con = FacesContext.getCurrentInstance(); 
    ExternalContext ex = con.getExternalContext(); 
    File file = new File(DIRECTORY_PATH_HERE + FILENAME_BERE); 

    ex.responseReset(); 
    ex.setResponseContentType("application/octet-stream"); 

    try { 
     ex.setResponseContentLength((int)file.length()); 
    } catch (IOException e) { 
     e.printStackTrace();  
    } 

    ex.setResponseHeader("Content-Disposition", "attachment; filename=\"" + FILE_NAME + "\""); 


    final HttpServletResponse res = (HttpServletResponse)excon.getResponse(); 
    ServletOutputStream out = res.getOutputStream(); 

    FileInputStream fs = new FileInputStream(file); 
    byte[] buf = new byte[ifs.available()]; 
    int i = 0; 

    while((i = fs.read(buf)) != -1){ 
     out.write(buf); 
    } 


    out.flush(); 
    out.close(); 
    fs.close(); 
    fc.responseComplete(); 
} 

도움이 되겠습니다. 고맙습니다. 당신이 JSF를 사용하는 경우

+0

당신이 너무 JSF 부분을 게시 할 수있는이 같은 것, 여러분의 인생을 더 쉽게 만드는 것입니다 당신이 유틸리티 라이브러리 omnifaces을 포함하는 것이 좋습니다 – Karim

답변

1

내가보기 엔 그것이 당신의 예

public void download() throws IOException { 
    Faces.sendFile(file, true); 
}