我正在尝试实现一个fileuploader。我使用java 7,primefaces 4和glassfish 3.1.2 我尝试按照帖子How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null的已接受答案中的说明进行操作 没有成功。 这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- Spring Context Configuration' s Path definition -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- The Bootstrap listener to start up and shut down Spring's root WebApplicationContext. It is registered to Servlet Container -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- JSF Servlet is defined to container -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Mapping with servlet and url for the http requests. -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<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>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>
继承人是我的.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
<ui:composition template="../template/Layout.xhtml">
<ui:define name="content">
<div class="frame">
<h:form id="originadorForm" enctype="multipart/form-data">
<p:growl id="growl" showDetail="true" life="3000" />
<p:fileUpload label="Cargar Imagen" fileUploadListener="#{originadorMB.handleFileUpload}" mode="advanced" update="growl" auto="true" sizeLimit="100000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
</h:form>
</div>
</ui:define>
</ui:composition>
</h:body>
</html>
并且heres是我的托管bean中的方法,它将执行上传:
public void handleFileUpload(FileUploadEvent event) {
FacesMessage msg = new FacesMessage("Exito", event.getFile().getFileName() + " fue subido. " + selectedOriginadoresListDTO.getImagen());
System.out.println(">>>>>>>>>>>>>" + selectedOriginadoresListDTO.getImagen() + " && " + event.getFile().getFileName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
问题是我的方法永远不会被调用。我在表单中添加了加密,并将过滤器添加到我的web.xml
,但没有成功。
我究竟做错了什么????
提前谢谢。