Struts檔案上傳

來源:互聯網
上載者:User

標籤:ext   tput   ***   nts   turn   tac   ram   font   絕對路徑   

如果檔案上傳不成功,預設是return "input"<result name="success">/success.jsp</result>    <result name="input">/index.jsp</result>單個檔案上傳ServletContext context=ServletActionContext.getServletContext();就是擷取webroot        String dir=context.getRealPath("/files/"+pptFileName);        System.out.println(dir);                FileOutputStream fos=new FileOutputStream(dir);        FileInputStream fis=new FileInputStream(ppt);                byte[] buffer=new byte[1024];        int len=0;        while ((len=fis.read(buffer))!=-1) {            fos.write(buffer, 0, len);        }                fos.close();        fis.close();上傳限制<interceptors>    <interceptor-stack name="fileUp">    <interceptor-ref name="defaultStack">    <param name="fileUpload.maximumSize">2000</param>    <param name="fileUpload.allowedTypes">text/plain,text/plain</param>    <param name="fileUpload.allowedExtensions">html,dtd,xml</param>    </interceptor-ref>    </interceptor-stack>    </interceptors>        image/png,image/bmp,image/jpg                      <default-interceptor-ref name="fileUp"></default-interceptor-ref><s:form action="s/upload_upload" method="post"            enctype="multipart/form-data" theme="simple">        <s:fielderror name="ppt"></s:fielderror>            file:<s:file name="ppt" label="file"></s:file>                pptDescA:<s:textfield name="pptDesc[0]" label="pptDescA"></s:textfield>while (iterator.hasNext()) {                File file = (File) iterator.next();                String dir=context.getRealPath("/resource/image/knowledge/upLoad/"+caseImgFileName.get(caseImg.));                System.out.println(dir+"***********dir");                try {                    fis=new FileInputStream(file);                    fos=new FileOutputStream(dir);                                        byte[] bs=new byte[1024];                    int len=0;                    while((len=fis.read(bs))!=-1){                        fos.write(bs, 0, len);                    }                                    } catch (FileNotFoundException e) {                    // TODO Auto-generated catch block                    System.out.println("檔案輸入錯誤");                } catch (IOException e) {                    // TODO Auto-generated catch block                    e.printStackTrace();                }finally{                    try {                        fos.close();                        fis.close();                    } catch (IOException e) {                        // TODO Auto-generated catch block                        System.out.println("輸入資料流、輸出資料流關閉錯誤");                    }                                    }            }
String rpath="resource/image/knowledge/upLoad/";儲存在資料庫中的路徑不能是絕對路徑一定要是相對路徑

 

Struts檔案上傳

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.