<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks
    Per some requests for the File Download opposite of File Upload.

    On the server side I implemented the doGet method of the HttpServlet class. I grab the raw data from the database and set it into the response (with the appropriate response type):

    BufferedOutputStream output = null;
    try {
    RawAttachmentItem attachment = attachmentFileDao.retrieveContents(fileid);
    ByteArrayInputStream input = new ByteArrayInputStream(attachment.getContents());
    int contentLength = input.available();

    resp.reset();
    resp.setContentType("application/octet-stream");
    resp.setContentLength(contentLength);
    resp.setHeader("Content-disposition", "attachment; filename=""" + attachment.getFilename()
    + """");
    output = new BufferedOutputStream(resp.getOutputStream());
    for(int data; (data=input.read()) != -1;) {
    output.write(data);
    }
    output.flush();
    }
    catch (IOException e) {

    e.printStackTrace();
    }
    finally {
    close(output);
    }
    On the client side, you simple create a new iFrame with its 'src' attribute set to the servlet url for downloading the file:

    boolean frameExists = (RootPanel.get("downloadiframe") != null);
    if(frameExists) {
    Widget widgetFrame = (Widget)RootPanel.get("downloadiframe");
    widgetFrame.removeFromParent();
    }

    NamedFrame frame = new NamedFrame("downloadiframe");
    frame.setUrl(GWT.getModuleBaseURL()
    + "/attachmentHandler?action=dl&fileid="
    + model.getFileId());
    frame.setVisible(false);

    RootPanel.get().add(frame);
    When the file gets sent back to the iFrame, the browser will treat it as a file download and prompt you to do something with it (open, save, cancel, etc).

    If anyone has questions or requires more detail, please do not hesitate to ask!!
    posted on 2010-02-01 21:21 seal 閱讀(626) 評論(0)  編輯  收藏 所屬分類: GWT
    主站蜘蛛池模板: 亚洲国模精品一区| 免费观看美女裸体网站| 亚洲欧洲自拍拍偷午夜色无码| 无码天堂亚洲国产AV| 国产精品嫩草影院免费| 婷婷亚洲综合五月天小说在线| 国产成人aaa在线视频免费观看 | A级毛片内射免费视频| 亚洲偷自精品三十六区| 四虎永久在线精品免费网址 | www.999精品视频观看免费| 亚洲国产成+人+综合| 99久久免费国产精品特黄| 久久亚洲国产最新网站| 永久黄网站色视频免费| 免费国产在线精品一区| 亚洲精品亚洲人成人网| 国产一区二区免费视频| 亚洲午夜久久久精品电影院| 女人18毛片特级一级免费视频| 国产AV无码专区亚洲AV琪琪| 2048亚洲精品国产| 国产精品免费一区二区三区四区| 亚洲美女视频免费| 在线免费一区二区| 国产精品免费看久久久香蕉| 亚洲高清视频在线观看| 99re热免费精品视频观看| 激情吃奶吻胸免费视频xxxx| 亚洲色精品aⅴ一区区三区| 在线看无码的免费网站| 亚洲日韩精品国产3区| 国产美女亚洲精品久久久综合| 久久国产高潮流白浆免费观看| 亚洲中文字幕无码久久| 亚洲精品人成无码中文毛片 | 99久久精品毛片免费播放| 亚洲欧洲精品视频在线观看| 国产又大又黑又粗免费视频 | 亚洲欧洲在线观看| 日韩精品无码人妻免费视频|