strus2使用commons-fileupload-1.3.1.jar工具包的圖片上傳,

來源:互聯網
上載者:User

strus2使用commons-fileupload-1.3.1.jar工具包的圖片上傳,

commons-fileupload-1.3.1.jar工具包的依賴包是commons-io-2.2.jar(FileUploaddepends on Commons IO, so make sure you have the version mentioned on thedependenciespage in your classpath before continuing.)

 

commons-fileupload-1.3.1.jar

在官網的wiki中解釋是:Commons-FileUploadmakes it easy to add robust, high-performance, file upload capability to yourservlets and web applications.即給檔案是與servlets原生支援的。關於怎麼在struts2中使用只能通過官網docs來學習了。

 

官網給出的demo

http://commons.apache.org/proper/commons-fileupload/streaming.html

 

我在這裡找到了Struts2的demo http://www.zuidaima.com/share/1833981853305856.htm

 

通過學習Struts2的demo我的問題解決了

以下貼出我自己的代碼:











成功後的:



值得注意的是檔案上傳之後副檔名變為temp,要在上傳之前對副檔名進行判斷。檔案上傳後的儲存目錄在struts.xml中有配置,檔案資訊是從jsp傳遞fileUpload到action中。






聯繫我們

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