2012-03-02 7 views
-2

私はeビジネス会社のために働いていて、私のプロジェクトリーダーが私にこのユースケースを教えてくれました... PLパッケージ(私はそれを行う方法は分かります)を呼び出して、出力パラメータ(pdfファイル名)私はサーバー内のファイルを参照してページに表示する必要があります...誰も考えを与えることができますか... ... Thanxk!PLパッケージから取得したページにPDFファイルを表示していますか?

+0

検索Googleで "サーブレットのダウンロードファイル" –

答えて

0

http://snippets.dzone.com/posts/show/4629から(Googleの "サーブレット・ダウンロード・ファイル" で検索した後):

private void doDownload(HttpServletRequest req, HttpServletResponse resp, 
         String filename, String original_filename) 
    throws IOException 
{ 
    File    f  = new File(filename); 
    int     length = 0; 
    ServletOutputStream op  = resp.getOutputStream(); 
    ServletContext  context = getServletConfig().getServletContext(); 
    String    mimetype = context.getMimeType(filename); 

    // 
    // Set the response and go! 
    // 
    // 
    resp.setContentType((mimetype != null) ? mimetype : "application/octet-stream"); 
    resp.setContentLength((int)f.length()); 
    resp.setHeader("Content-Disposition", "attachment; filename=\"" + original_filename + "\""); 

    // 
    // Stream to the requester. 
    // 
    byte[] bbuf = new byte[BUFSIZE]; 
    DataInputStream in = new DataInputStream(new FileInputStream(f)); 

    while ((in != null) && ((length = in.read(bbuf)) != -1)) 
    { 
     op.write(bbuf,0,length); 
    } 

    in.close(); 
    op.flush(); 
    op.close(); 
} 
関連する問題