<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 閱讀(619) 評論(0)  編輯  收藏 所屬分類: GWT
    主站蜘蛛池模板: 亚洲日本中文字幕天堂网| 亚洲精品私拍国产福利在线| 国产免费久久精品99久久| 亚洲国产成人精品无码区在线观看| 中文字幕视频免费| 久久精品国产亚洲av天美18 | 成人免费无码大片a毛片| 国产亚洲视频在线| 亚洲自偷自偷精品| 亚洲va中文字幕无码| 精品熟女少妇av免费久久| 视频一区二区三区免费观看| 久久久亚洲欧洲日产国码是AV| 日本特黄a级高清免费大片| 久久国产精品免费视频| 国产亚洲精品免费| 亚洲沟沟美女亚洲沟沟| 亚洲精品国产电影| 好男人www免费高清视频在线| 最近免费中文字幕中文高清| 亚洲精品欧美综合四区| 亚洲欧洲第一a在线观看| 免费国产小视频在线观看| 成人免费视频69| a级片免费在线观看| 亚洲av无码成人影院一区| 亚洲AV无码成人精品区天堂| 凹凸精品视频分类国产品免费| 1区2区3区产品乱码免费| 日日摸夜夜添夜夜免费视频| 亚洲人成综合网站7777香蕉| 亚洲avav天堂av在线不卡| 亚洲免费视频一区二区三区| 在线观看免费a∨网站| 91福利视频免费| 免费人成网站在线观看不卡| 国产精品亚洲专区在线播放| 亚洲国产日韩精品| 亚洲人成人77777在线播放| 91久久亚洲国产成人精品性色| 亚洲中文字幕无码一区|