Primefaces+;spring文件上传

Primefaces+;spring文件上传,primefaces,Primefaces,我在文件上传中得到空值我的代码如下。。。。请检查并让我知道遗漏了什么 @Component("businessInformationBean") @Scope("view") public class BusinessInformationBean extends AbstractBaseBean { private static final Logger LOGGER = Logger .getLogger(BusinessInformationBean.cl

我在文件上传中得到空值我的代码如下。。。。请检查并让我知道遗漏了什么

@Component("businessInformationBean")
@Scope("view")
public class BusinessInformationBean extends AbstractBaseBean {

    private static final Logger LOGGER = Logger
            .getLogger(BusinessInformationBean.class);

    private static final long serialVersionUID = 1L;

    @Autowired
    private BusinessInformationService businessInformationService;

    @Value("#{addressBean}")
    private AddressBean address;

    private String firmName;
    private Date openingDate;
    private Date activityDate;
    private String businessType;
    private Date seasonStartDate;
    private Date seasonEndDate;
    private Date closerDate;
    private String natureOfBusiness;
    private UploadedFile file;
    private String bankAccholdername;
    private String bankName;
    private String bankBranchName;
    private String accountNumber;
    private String accountType;
    private String bankAddress;
    private String bankIFSCCode;
    private String bankCity;
    private String bankDistrict;
    private String bankState;
    private Integer bankZipcode;


    public void save(ActionEvent event) {
        LOGGER.info("businessInformationBean Save");
        try
        {
            FacesContext fc = getFacesContext();

            if (frmValidation())
            {
                MmBusinessInformation businessInformation = businessInformationService
                        .fetchBusinessInformationServiceByLoginUser(getCurrentUser());
                mapWebBackToDomain(businessInformation);
                businessInformationService.saveOrUpdate(businessInformation);
                renderRecordSaveMessage();
            }
            else
            {
                fc.renderResponse();
            }
        } 
        catch (Exception e)
        {
            LOGGER.error(e.getMessage());
            renderFatalError();
        }
    }

    public UploadedFile getFile() {
        return file;
    }

    public void setFile(UploadedFile file) {
        this.file = file;
    }
my 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" id="WebApp_ID" version="3.0">
   <display-name>ems-web</display-name>
   <welcome-file-list>
      <welcome-file>login.xhtml</welcome-file>
   </welcome-file-list>

   <!-- Change to "Production" when you are ready to deploy -->
   <context-param>
      <param-name>javax.faces.PROJECT_STAGE</param-name>
      <param-value>Development</param-value>
   </context-param>
   <context-param>
      <param-name>primefaces.THEME</param-name>
      <param-value>redmond</param-value>
   </context-param>
   <!-- Spring Security Facelets Tag Library -->
    <context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
    </context-param>

   <context-param>
      <param-name>primefaces.FONT_AWESOME</param-name>
      <param-value>true</param-value>
   </context-param>
   <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>            
            /WEB-INF/applicationContext.xml
            /WEB-INF/security-context.xml
        </param-value>
    </context-param>
   <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
   <listener>
      <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
   </listener>
   <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>



<filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
        <init-param>
            <param-name>uploadDirectory</param-name>
            <param-value>/home/alekss/uploads</param-value>
        </init-param>
        <init-param>
            <description>Maximum size of stored in memory file</description>
            <param-name>thresholdSize</param-name>
            <param-value>10240000</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>







   <filter>
      <filter-name>hibernateFilter</filter-name>
      <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
   </filter>
   <filter-mapping>
      <filter-name>hibernateFilter</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>

    <!-- Spring security filter -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
       <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>

    </filter-mapping>   
</web-app>

ems网络
login.xhtml
javax.faces.PROJECT_阶段
发展
主题
雷德蒙
javax.faces.FACELETS\u库
/WEB-INF/springsecurity.taglib.xml
primefaces.FONT\u太棒了
真的
上下文配置位置
/WEB-INF/applicationContext.xml
/WEB-INF/security-context.xml
org.springframework.web.context.ContextLoaderListener
org.springframework.web.context.request.RequestContextListener
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
*.xhtml
PrimeFaces文件上载筛选器
org.primefaces.webapp.filter.FileUploadFilter
上传目录
/主页/alekss/上传
存储在内存中的文件的最大大小
阈值大小
10240000
PrimeFaces文件上载筛选器
Facesservlet
冬眠过滤器
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
冬眠过滤器
/*
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
向前地
要求
下面是.xhtml文件中的代码

 <p:fileUpload id="fileUp" fileUploadListener="#{businessInformationBean.file}" mode="commons" />

请给我一些建议,遗漏了什么…这让我很困惑。。。
提前感谢。

p:fileUpload中的fileUploadListener属性需要一个带有FileUploadEvent参数的方法,如下所示:

public void handleFileUpload(FileUploadEvent event) {   
    //try {
        UploadedFile uf = event.getFile();
        //uf.getFileName();
        //uf.getInputstream();

    //} catch (IOException e) {
        //Do something
    //}
}


然后,您可以获得流、文件名等

还要检查表单是否具有enctype属性

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


谢谢达沃:)是的,工作顺利,谢谢回复:)让我分享一下我的整个情况。。。我有一张表格。。。[name/idProfImage/address/image]为此,我需要两个文件上载控制器。。。。由于此文件上载控制其上载时上载按钮单击“我对primefaces是新的:”)那么您有什么建议吗?我只想在save()方法中获取图像obj,以便我可以继续使用其他表单数据进行保存……在handleFileUpload方法中,您可以设置控制器/bean变量file=event.getFile();然后在save方法中,您可以获取file变量以获取流file.getInputStream()
<h:form id="myForm" enctype="multipart/form-data">