<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无码专区亚洲AV伊甸园 | 青苹果乐园免费高清在线| 免费永久看黄在线观看app| 久久亚洲精品视频| 亚洲性无码一区二区三区| 亚洲精品自在在线观看| 亚洲一区二区三区91| 无遮挡国产高潮视频免费观看| 99久久久国产精品免费牛牛四川| 日本特黄特色免费大片| 久久久久亚洲精品美女| 国产午夜亚洲精品不卡| 精品一区二区三区无码免费视频 | 亚洲精品美女视频| 人体大胆做受免费视频| 无码国产精品一区二区免费 | 亚洲国产美女福利直播秀一区二区| 美女露隐私全部免费直播| 亚洲免费中文字幕| 国产精品亚洲w码日韩中文| 国产成人精品亚洲日本在线| a毛片全部播放免费视频完整18| 成人毛片手机版免费看| 亚洲av女电影网| 免费一级毛片在线播放放视频 | 亚洲精品国产字幕久久不卡| 亚洲乱色熟女一区二区三区蜜臀| 精品免费视在线观看| 免费国产成人午夜私人影视| 亚洲伊人久久大香线蕉| 成全高清在线观看免费| 国产一级一片免费播放i| 亚洲国产精品yw在线观看| 18禁在线无遮挡免费观看网站| 国产成人无码a区在线观看视频免费 | 国产免费看JIZZ视频| 日韩免费高清视频网站| 亚洲网红精品大秀在线观看| 中文字幕在线免费观看视频| 国产大片51精品免费观看|