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

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

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

    vjame

    優化代碼是無止境的
    隨筆 - 65, 文章 - 9, 評論 - 26, 引用 - 0
    數據加載中……

    使用FormFile處理文件上傳下載

    1.首先界面設計,自己搞定 .。。。



    2. 然后在jsp頁面中定義文件上傳標簽,name 要和From中定義的FormFile變量名稱一致



    3. 在Form中定義FormFile私有變量, 它和文件上傳標簽名稱要一樣。



    4.  ,這里要先在po類里面定義個字節變量content 接收上傳來的文件內容


    5. 在Action的增加方法中,首先判斷頁面上是否有文件被上傳,然后把內容設置到po類里面去 ,這里getFileData()得到的是字節.

    6. 文件需要提交下載時,在Action中加入一下代碼

        //下載公文附件
        public ActionForward download(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
            
            DocumentActionForm daf 
    = (DocumentActionForm)form;
            
            Document document 
    = documentManager.findDocument(daf.getId());
            
            response.reset();
            response.setContentType(
    "application/x-download;charset=GBK");
            response.setHeader(
    "Content-Disposition""attachment;filename=temp.doc");
            
            response.getOutputStream().write(document.getContent());
            
            response.getOutputStream().flush();
            response.getOutputStream().close();
            
            
    //指示struts,不要對返回值進行處理
            return null;
        }

    7. 程序運行效果
    另外一種方法在Action中添加download方法也是可以達到下載功能的目的
        public ActionForward downloadFile(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) 
    throws Exception{

            String docId 
    = request.getParameter("docId");
            Doc doc 
    = baseService.find(docId);
            SerializableBlob serBlob 
    = null;
            
    if(doc!= null){
                serBlob 
    = (SerializableBlob) doc.getContentBinary();
            }

            Blob blob 
    = serBlob.getWrappedBlob();
            
    try {
                
    if (blob != null) {
                    response.reset();
                    BufferedInputStream in 
    = new BufferedInputStream(
                            blob.getBinaryStream()); 
    // 輸入流
                    response.setContentType("bin:charset=utf-8");
                    response.setHeader(
                                    
    "Content-Disposition",
                                    
    "attachment; filename=temp.doc"); // 設置保存頁面提示信息
                    byte[] b = new byte[100];
                    
    int len;
                    
    while ((len = in.read(b)) > 0) {
                        response.getOutputStream().write(b, 
    0, len);
                    }
                    in.close();
                }
            } 
    catch (Exception e) {
                
    return null;
            }
            
    return null;
        }

    posted on 2008-11-07 01:24 lanjh 閱讀(3003) 評論(0)  編輯  收藏 所屬分類: Java Web

    主站蜘蛛池模板: 亚洲男人都懂得羞羞网站| 亚洲综合激情另类专区| 亚洲日本香蕉视频| 免费在线看黄网站| 国产亚洲一区二区手机在线观看| 国产成人亚洲精品91专区高清| 女人被男人桶得好爽免费视频| 亚洲国产成人91精品| 麻豆一区二区免费播放网站| 亚洲高清日韩精品第一区| 最近中文字幕2019高清免费| 久久精品蜜芽亚洲国产AV| 亚洲一级免费毛片| 亚洲人成电影在线观看青青| 手机看黄av免费网址| 中文字幕无码精品亚洲资源网久久 | 香蕉97碰碰视频免费| 亚洲第一区精品日韩在线播放| 成人精品综合免费视频| 亚洲国产精品热久久| 久久精品免费全国观看国产| 亚洲人成色在线观看| 在线观看91精品国产不卡免费| 大片免费观看92在线视频线视频| 在线精品亚洲一区二区小说| 中文字幕免费不卡二区| 91嫩草亚洲精品| 日本黄页网站免费| 99免费在线视频| 亚洲性猛交xx乱| 内射无码专区久久亚洲| 久久精品成人免费观看97| 在线观看亚洲人成网站| 精品久久久久久久免费人妻| 国产在线国偷精品免费看| 亚洲国产成+人+综合| 免费a级毛片大学生免费观看| 七色永久性tv网站免费看| 国产日本亚洲一区二区三区| 中文字幕不卡亚洲| 免费的一级黄色片|