【发布时间】:2012-04-15 09:21:20
【问题描述】:
监听器没有响应我的操作:
<h:form>
<p:fileUpload mode="simple" fileUploadListener="#{ADD.uploadImage}" auto="true"/>
</h:form>
这是支持 bean:
@ManagedBean
@ViewScoped
public class TestClass {
public void uploadImage(FileUploadEvent e){
System.out.println("EVENT");
}
}
这是我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/tmpDir3/</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>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
问题在于方法uploadImage 没有被调用。
我的代码有什么问题或缺少什么?
【问题讨论】:
-
你的表单是 enctype="multipart/form-data" 吗,像这样:
-
我在日志 tomcat 01/04/2012 01:00:57 有这个异常 org.apache.catalina.core.StandardWrapperValve 调用 SEVERE: Servlet.service() for servlet [Faces Servlet] in带有路径 [/UploadedImageTest] 的上下文抛出异常 java.io.IOException:处理多部分/表单数据请求失败。 \tmpDir\upload__5e4873ce_1366d8db020__8000_00000020.tmp(系统找不到指定的路径)
-
是的,我的表单中有这一行
-
找不到你的上传目录...尝试改成
/tmpDir3 (去掉一个/) -
你找对了豆子吗?你的绑定说
#{ADD.uploadImage},但你显示的bean将被称为testClass,而不是ADD。
标签: java jquery ajax jsf jsf-2