gpt4 book ai didi

jsf - Primefaces 3.0文件上传不调用fileUploadListner

转载 作者:行者123 更新时间:2023-12-01 13:34:58 24 4
gpt4 key购买 nike

我正在尝试根据演示中给出的示例对 Primefaces 3.0 的文件上传组件进行上传。我还在部署在 JBoss 6.1 上的应用程序中添加了 commons-fileupload-1.2.2.jar 和 commons-io-2.0.1.jar 以及 primefaces-3.1.jar 文件。

问题是没有调用 handleFileUpload()。

<?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">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
/context-param>
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-value>server</param-value>
</context-param>
<!--Humanity theme for PrimeFaces -->
<context-param>
<param-name>primefaces.THEME</param-name>
</context-param>

<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
<init-param>
<param-name>uploadDirectory</param-name>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>




<h:body>
<h:form enctype="multipart/form-data">

<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced"
update="messages"
sizeLimit="500000"
description="select template"
allowTypes="/(\.|\/)(doc|docx)$/"/>

<p:growl id="messages" showDetail="true"/>

</h:form>

/h:body>
</html>

文件上传 Controller .java

导入javax.faces.application.FacesMessage;导入 javax.faces.context.FacesContext;

导入 org.primefaces.event.FileUploadEvent;导入 org.primefaces.model.UploadedFile;

public class FileUploadController {

public void handleFileUpload(FileUploadEvent event) {
System.out.println("**** Inside handleFileUpload() ***** ");
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}

最佳答案

PrimeFaces 文件上传过滤器需要映射到 FacesServlet

您已经声明了 FacesServlet 的 servlet 名称,如下所示:

<servlet-name>FacesServlet</servlet-name>

但是,PrimeFaces 文件上传过滤器映射到错误的 servlet 名称(注意空格):

<servlet-name>Faces Servlet</servlet-name>

相应地修复它。

另见:

关于jsf - Primefaces 3.0文件上传不调用fileUploadListner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9587604/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com