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

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

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

    Java學(xué)習(xí)

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

     

    JSF 下載文件 怎么實(shí)現(xiàn)

     
     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 自動(dòng)生成 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 找個(gè)美女做老婆 閱讀(1672) 評(píng)論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

    統(tǒng)計(jì)

    公告

    本blog已經(jīng)搬到新家了, 新家:www.javaly.cn
     http://www.javaly.cn

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 在线精品亚洲一区二区| 亚洲av片一区二区三区| 亚洲中文字幕无码一去台湾 | 亚洲字幕AV一区二区三区四区| 成年女性特黄午夜视频免费看| 日本一区二区三区在线视频观看免费 | 一道本在线免费视频| 精品亚洲国产成AV人片传媒| 免费在线观看中文字幕| 韩国免费一级成人毛片| 国产精品美女久久久免费 | 四虎影视永久免费观看地址| 中文精品人人永久免费| 亚洲精品无码久久久久A片苍井空 亚洲精品无码久久久久YW | 亚洲av永久无码精品漫画| 成年人免费视频观看| 久久精品国产大片免费观看| 亚洲a∨无码精品色午夜| 亚洲国产日产无码精品| 亚洲色偷偷偷鲁综合| 国产成人综合久久精品亚洲| 亚洲一级毛片中文字幕| 中文字幕无码免费久久| 极品色天使在线婷婷天堂亚洲| 亚洲乱码日产精品BD在线观看| 亚洲国产精品特色大片观看完整版| 亚洲精品无码久久久久久| 亚洲制服丝袜精品久久| 99热在线观看免费| 青青操免费在线视频| 亚洲最大av无码网址| 波多野结衣一区二区免费视频| 亚洲一区二区三区久久久久| a级毛片免费完整视频| 亚洲视频在线免费| jizz在线免费播放| 国产成人精品亚洲| 黄色免费网址在线观看| 好爽好紧好大的免费视频国产| 丁香花在线观看免费观看 | 无遮挡国产高潮视频免费观看|