2012-01-30 3 views
0

내 Struts2 응용 프로그램에서 파일 이름 목록에 해당 파일 이름을 cliking하면 file.here 파일 이름이 db에서옵니다. 그것을 위해 난 오픈 FILESTREAM (struts2의 filedownalod) 코드를 기록한하면 FileDownload 액션Struts2에서 동적 파일 다운로드

<iterator list... 
<a href="filedownload.action?filepath=${filepath}>${filepath} </a> 
</iterator... 

처럼 부호화있다.

Firefox7 이상을 제외한 모든 브라우저에서 작동합니다. 그 던지는 **"Content correpted Error"**.

답변

1

URL 인코딩과 관련된 문제가 있다고 생각합니다. 경로를 매개 변수로 전달하는 것이 좋다고 생각하지 않습니다. 데이터베이스에 ID를 전달하여 FileInputStream에서 다운로드하는 것이 안전합니다. 최소한 권한이 부여 된 파일을 다운로드하려고 할 때 사용자의 권한을 확인할 수 있습니다.

I는 다음과 같이 할 것 :

Action 클래스

public String download() throws Exception { 

    fileName = getFromDatabaseById(id); 

    try 
    { 
     fileInputStream = new FileInputStream(new File(FILE_FOLDER + filename)); 
    } 
    catch(FileNotFoundException ex) 
    { 
     logger.error(this.getClass().getSimpleName() + ": File in " + FILE_FOLDER + filename + " cannot be found."); 
      return ERROR; 
     } 

     return DOWNLOAD; 
} 

그리고 당신의 struts.xml에서

<iterator list... 
<a href="filedownload?id=%{id_in_the_database} </a> 
</iterator... 

<action name="filedownload" method="download" class="com.yourproject.filedownload"> 
    <result name="download" type="stream"> 
     <param name="contentType">application/octet-stream</param> 
     <param name="inputName">fileInputStream</param> 
     <param name="contentDisposition">attachment;filename=%{filename}</param> 
     <param name="bufferSize">4096</param> 
    </result> 
    <result name="error" type="redirectAction">erroraction</result> 
</action> 
관련 문제