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

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

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

    Java學習

    java,spring,structs,hibernate,jsf,ireport,jfreechart,jasperreport,tomcat,jboss -----本博客已經搬家了,新的地址是 http://www.javaly.cn 如果有對文章有任何疑問或者有任何不懂的地方,歡迎到www.javaly.cn (Java樂園)指出,我會盡力幫助解決。一起進步

     

    JSF 下載文件 怎么實現

     
     java code ::

    ----------------------------------

    package demo;


    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.UnsupportedEncodingException;
    import java.net.URLDecoder;
    import java.util.logging.Logger;

    import javax.faces.application.Application;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServletResponse;

    import org.operamasks.faces.annotation.ManagedBean;
    import org.operamasks.faces.annotation.ManagedBeanScope;
    @ManagedBean(name
    ="downFile", scope=ManagedBeanScope.SESSION)
    public class DownFile {
    public String download() {
    //OaMailAttach oaMailAttach = getOaMailAttach();

    String path
    ="G:\\sun\\";
    String fileName
    ="20074111452140.doc";

    try {
    FacesContext ctx
    = FacesContext.getCurrentInstance();
    ctx.responseComplete();
    //String contentType = "application/octet-stream;charset=utf-8";
    String contentType = "application/x-download";
    HttpServletResponse response
    = (HttpServletResponse) ctx.getExternalContext().getResponse();



    response.setContentType(contentType);

    StringBuffer contentDisposition
    = new StringBuffer();

    contentDisposition.append(
    "attachment;");

    contentDisposition.append(
    "filename=\"");
    contentDisposition.append(fileName);
    contentDisposition.append(
    "\"");
    //log.debug(System.getProperty("file.encoding"));
    response.setHeader("Content-Disposition", new String(contentDisposition.toString().getBytes(System.getProperty("file.encoding")),"iso8859_1"));
    // log.debug(contentDisposition.toString());
    ServletOutputStream out = response.getOutputStream();

    //log.debug(new Long(oaMailAttach.getAtFile().length()));

    byte[] bytes = new byte[0xffff];
    InputStream is
    = new FileInputStream(new File(path + fileName));
    int b = 0;
    while ((b = is.read(bytes, 0, 0xffff)) > 0) {
    out.write(bytes,
    0, b);
    }
    is.close();
    out.flush();
    ctx.responseComplete();
    }
    catch (Exception e) {
    // TODO 自動生成 catch 塊
    e.printStackTrace();
    }
    return null;
    }


    -------------------------------------------------------------------------

    <%@ page contentType="text/html;charset=UTF-8"%>
    <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
    <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
    <%@ taglib prefix="l" uri="http://www.apusic.com/jsf/layout" %>
    <%@ taglib prefix="ajax" uri="http://www.apusic.com/jsf/ajax" %>
    <%@ taglib prefix="w" uri="http://www.apusic.com/jsf/widget" %>
    <f:view >
    <w:page title="Stock Quote" skin="aqua">
    <h:head>
    <style type="text/css">
    #grid
    -example {
    height:280px;
    border:1px solid #cbc7b8;
    }
    #stock
    -detail {
    width:400px;
    }
    </style>
    <w:stylesheet src="/common/resources/examples.css"/>
    </h:head>
    <h:form>
    <h:commandLink id="file1" value="下載文件" action="#{downFile.download}" type="button">
    </h:commandLink>
    </h:form>

    </w:page>
    </f:view>


    }

    posted on 2008-08-22 10:35 找個美女做老婆 閱讀(1679) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    公告

    本blog已經搬到新家了, 新家:www.javaly.cn
     http://www.javaly.cn

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产亚洲精久久久久久无码| 成人毛片18岁女人毛片免费看| 免费一级做a爰片久久毛片潮喷| 亚洲一级黄色大片| 日韩精品亚洲aⅴ在线影院| 国产亚洲一卡2卡3卡4卡新区| 暖暖免费高清日本中文| 亚洲AV无码一区二区三区牲色| 四虎www成人影院免费观看| 亚洲av永久无码一区二区三区| 免费黄色一级毛片| 亚洲欧美在线x视频| 亚洲A∨精品一区二区三区| 日韩在线视频免费| 国产亚洲福利精品一区| 日韩免费在线观看视频| 亚洲欧洲春色校园另类小说| 青娱乐免费在线视频| 亚洲爆乳无码精品AAA片蜜桃| 免费久久精品国产片香蕉| 国产午夜无码片免费| 亚洲欧洲综合在线| 日韩免费a级在线观看| 亚洲免费无码在线| 91亚洲国产成人精品下载| 麻豆最新国产剧情AV原创免费| 亚洲AV无码成人精品区狼人影院 | 亚洲视频在线观看网址| 一个人看的www在线观看免费| 亚洲AV无码国产一区二区三区 | 亚洲综合网站色欲色欲| 99视频有精品视频免费观看| 亚洲kkk4444在线观看| 亚洲第一页日韩专区| 99热在线免费播放| 亚洲午夜成人精品无码色欲| 中文字幕不卡亚洲| 免费看黄视频网站| 一级一级毛片免费播放| 成人无遮挡裸免费视频在线观看| 亚洲av无码专区在线电影天堂|