<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
    主站蜘蛛池模板: 久久亚洲精品无码av| 精品亚洲麻豆1区2区3区| 亚洲天然素人无码专区| 69视频免费在线观看| 亚洲天堂视频在线观看| 人妻无码久久一区二区三区免费 | 男男gay做爽爽免费视频| 免费的一级片网站| 永久在线观看www免费视频| 久久精品国产亚洲AV麻豆不卡 | 亚洲四虎永久在线播放| 久久久久免费精品国产小说| 久久亚洲美女精品国产精品| 91老湿机福利免费体验| 亚洲成年人免费网站| 成年男女免费视频网站| 亚洲AV成人无码网天堂| 亚洲国产精品国产自在在线 | 亚洲免费人成视频观看| 永久免费的网站在线观看| 亚洲人成自拍网站在线观看| 成全影视免费观看大全二| 国产亚洲日韩在线a不卡| 国产黄色一级毛片亚洲黄片大全| 中文字幕免费在线看线人动作大片 | 亚洲午夜成人精品无码色欲| 国产jizzjizz免费视频| 91av免费在线视频| 亚洲国产精久久久久久久| 精品久久久久国产免费| 深夜a级毛片免费视频| 亚洲无线码在线一区观看| 亚洲国产精品免费在线观看| 亚洲丶国产丶欧美一区二区三区| 亚洲日韩VA无码中文字幕| 四虎国产精品永久免费网址| 亚洲高清中文字幕免费| 国产午夜亚洲不卡| 午夜宅男在线永久免费观看网| 特级毛片全部免费播放a一级 | 亚洲免费在线观看视频|