日期:2014-05-16 浏览次数:20292 次
primeface-2.2.RC2.jar jsf-api-2.0.2.jar jsf-impl-2.0.2.jar el-api-2.2.jar el-impl-2.2.jar commons-io-1.4.jar commons-fileupload-1.2.jar
<!-- File Upload --> <filter> <filter-name>PrimeFaces FileUpload Filter</filter-name> <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> <init-param> <param-name>thresholdSize</param-name> <param-value>2097152</param-value> </init-param> </filter> <filter-mapping> <filter-name>PrimeFaces FileUpload Filter</filter-name> <servlet-name>faces-servlet</servlet-name> </filter-mapping> <servlet> <servlet-name>faces-servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>faces-servlet</servlet-name> <url-pattern>*.xhtml</url-pattern> </servlet-mapping>
<h:form id="uploadForm"> <p:fileUpload id="upload" fileUploadListener="#{blackListImportBean.handleFileUpload}" multiple="true" allowTypes="*.xls;*.xlsx" description="*.xls;*.xlsx" sizeLimit="10000000000"/> </h:form>
public void handleFileUpload(FileUploadEvent event) { System.out.println("Handling Upload: " + event.getFile()); UploadedFile upload = event.getFile(); FacesContext.getCurrentInstance().addMessage("", new FacesMessage(FacesMessage.SEVERITY_INFO, "File Uploaded", "This file is " + upload)); //do whatever here.... }