JSP複習筆記——檔案上傳

來源:互聯網
上載者:User

標籤:ar   io   os   使用   sp   for   java   on   檔案   

SmartUpload主要的功能是上傳檔案
上傳圖片,可以通過SmartUpload實現

1、 配置smartupload.jar
tomcat/common/lib
2、 可以進行開發

對於上傳圖片,一般檔案較大,使用post
如果要上傳圖片,需要對錶單的資料進行封裝
<form action="sample01.jsp" method="post" ENCTYPE="multipart/form-data">選擇要上傳的圖片:<input type="file" name="pic"><input type="submit" value="上傳"></form>

<jsp:useBean id="smart" scope="page" class="com.jspsmart.upload.SmartUpload"/><%// 1、上傳初始化smart.initialize(pageContext) ;// 2、準備上傳smart.upload() ;// 3、儲存上傳的檔案smart.save("/upload") ;%><h1>輸入的名稱為上傳後的名稱</h1><form action="sample03.jsp" method="post" ENCTYPE="multipart/form-data">輸入名稱:<input type="text" name="name"><br>選擇要上傳的圖片:<input type="file" name="pic"><br><input type="submit" value="上傳"></form><jsp:useBean id="smart" scope="page" class="com.jspsmart.upload.SmartUpload"/><%// 1、上傳初始化smart.initialize(pageContext) ;// 2、準備上傳smart.upload() ;// 3、儲存上傳的檔案// smart.save("/upload") ;// 得到副檔名稱String ext = smart.getFiles().getFile(0).getFileExt() ;%><%// 不能直接使用request對象,通過smart.getRequest()取得String name = smart.getRequest().getParameter("name") ;%><%// 儲存檔案smart.getFiles().getFile(0).saveAs("/upload/"+name+"."+ext) ;%>

JSP複習筆記——檔案上傳

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.