程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> Primefaces 3.4.2 "文件上傳"的總結

Primefaces 3.4.2 "文件上傳"的總結

編輯:關於JSP

(1)Jars   添加commons-fileupload-1.2.2.jar and commons-io-1.4.jar到web-inf/lib目錄下     (2)web.xml   添加如下配置到web.xml中     <filter>     <filter-name>PrimeFaces FileUpload Filter</filter-name>     <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> </filter> <filter-mapping>     <filter-name>PrimeFaces FileUpload Filter</filter-name>     <servlet-name>Faces Servlet</servlet-name> </filter-mapping>(3)*.xhtml        [html]   <SPAN style="FONT-SIZE: 14px"><h:form enctype="multipart/form-data">       <p:fileUpload value="#{fileBean.uploadedFile}" mode="simple" />       <p:commandButton value="Submit" ajax="false"/>   </h:form></SPAN>     <h:form enctype="multipart/form-data">     <p:fileUpload value="#{fileBean.uploadedFile}" mode="simple" />     <p:commandButton value="Submit" ajax="false"/> </h:form> Note:(1)Please note the enctype="multipart/form-data" attribute of the form. This is mandatory for HTML in order to be able to send files to the server. The filter is mandatory for JSF in order to extract the data from multipart/form-data requests. Without either of them, either the command action won't be invoked, or all properties will be null.            (2)simple upload doesn't support ajax.  should add ajax="false" on commondButton     (4)Manager Bean                [java]  <SPAN style="FONT-SIZE: 14px">public class FileUploadController {             private UploadedFile uploadedFile;          public FileUploadController() {       }                 public UploadedFile getUploadedFile() {           return uploadedFile;       }          public void setUploadedFile(UploadedFile uploadedFile) {           this.uploadedFile = uploadedFile;       }          public void submit() {               // Get information you from the uploaded file            System.out.println("Uploaded file name : " + uploadedFile.getFileName());       }      } </SPAN>     public class FileUploadController {          private UploadedFile uploadedFile;       public FileUploadController() {     }              public UploadedFile getUploadedFile() {         return uploadedFile;     }       public void setUploadedFile(UploadedFile uploadedFile) {         this.uploadedFile = uploadedFile;     }       public void submit() {             // Get information you from the uploaded file         System.out.println("Uploaded file name : " + uploadedFile.getFileName());     }   }  在寫這篇文章時,還有個問題沒有解決,就是上傳文件的名稱為中文時,保存的文件名為亂碼,期待完善中.      

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved