<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
    主站蜘蛛池模板: 亚洲国产a∨无码中文777| 亚洲中文字幕无码永久在线| 亚洲国产综合第一精品小说| a在线免费观看视频| 亚洲色中文字幕无码AV| 国产精品午夜免费观看网站| 久久亚洲国产精品123区| 国产黄色片免费看| 亚洲AV无码欧洲AV无码网站| 久久成人免费大片| 亚洲国产成人精品无码一区二区| 国产精彩免费视频| 国产精品亚洲一区二区麻豆| 日本高清免费不卡视频| 手机永久免费的AV在线电影网| 在线亚洲午夜理论AV大片| 精品国产一区二区三区免费| 亚洲精品国产电影午夜| 成人网站免费观看| 羞羞网站免费观看| 亚洲成av人在线视| 日本亚洲免费无线码| 亚洲成a人片在线不卡一二三区 | 五月天国产成人AV免费观看| 亚洲综合AV在线在线播放| 久久久免费的精品| 亚洲欧美国产日韩av野草社区| www国产亚洲精品久久久| a视频在线观看免费| 亚洲国产成人精品青青草原| 国产又长又粗又爽免费视频| 国产色无码精品视频免费| 亚洲国产精品久久久久秋霞影院| 精品久久久久久久免费加勒比| 国产无限免费观看黄网站| 亚洲电影免费观看| 国产极品美女高潮抽搐免费网站| a级黄色毛片免费播放视频| 中文字幕在线日亚洲9| 永久亚洲成a人片777777| 丁香花免费高清视频完整版|