2012-08-10 47 views
4

我的問題是我無法顯示使用Struts2在jsp上生成的pdf。在Jsp中使用Struts2顯示PDF

我能夠生成動態使用動態碧玉在Struts2,也能

下載使用它的

結果類型=「流」唯一的問題我停留在PDF中顯示PDF在jsp中。我能夠

顯示它使用IFRAME標記,但它顯示舊的PDF不是我在運行時生成的。

如果任何人有任何建議都幫助我在此先感謝

+1

問題解決了剛給直列在內容處理 – 2012-08-10 14:28:11

+1

您可以在此發佈您的解決方案,以便它可以幫助其他SO用戶 – 2012-08-13 05:09:48

+0

確定我的榮幸 – 2012-08-14 15:00:49

回答

4
Action Class 

public class GeneratePdf extends ActionSupport 
{ 
    public InputStream inputStream; 
    File file = new File("D:\\workspace\\desktopApp\\HRIS_Updated\\WebContent\\Jasper\\hris.employee.report.AwardReport.pdf"); 
    public String execute(){ 

      try { 

      inputStream = new DataInputStream(new FileInputStream(file)); 

     } catch (FileNotFoundException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    return SUCCESS; 
} 
public void setInputStream(InputStream inputStream) { 
     this.inputStream = inputStream; 
    } 



public InputStream getInputStream() { 
     return inputStream; 
    } 
} 

在.xml文件

<action name="GeneratePdf" class="hris.report.action.GeneratePdf"> 
      <result name="success" type="stream"> 
       <param name="contentType">application/pdf</param> 
       <param name="inputName">inputStream</param> 
       <param name="contentDisposition">inline;filename="test.pdf"</param> 
       <param name="bufferSize">1024</param> 
      </result> 
     </action> 

希望它能幫助:)