我正在尝试使用JSF创建文件上传器。我在各种论坛上提到过几篇文章,但没有任何效果,所以我觉得,可能还有其他一些案例并发布了。我在表单中使用enctype,我有commons-IO和commons-fileupload,我在web.xml中添加了适当的过滤器。但它仍然不起作用并抛出NullPointerException。
<h:form id="expenseForm" enctype="multipart/form-data"">
<table class="table table-condensed table-bordered table-hover table-striped">
<tr>
<td><h:outputText value="#{BHMaintenanceController.getSelectedLanguageLabel('Reason For Expense')}"/></td>
<td><p:inputText value="#{BHMaintenanceController.newExpense.reason}"/></td>
</tr>
<tr>
<td><h:outputText value="#{BHMaintenanceController.getSelectedLanguageLabel('Total Expense')}"/></td>
<td><p:inputText value="#{BHMaintenanceController.newExpense.expense}"/></td>
</tr>
<tr>
<td><h:outputText value="#{BHMaintenanceController.getSelectedLanguageLabel('Upload Receipt')}"/></td>
<td><p:fileUpload value="#{BHMaintenanceController.expense_receipt}" mode="simple" skinSimple="true"/></td>
</tr>
</table>
<p:commandButton value="#{BHMaintenanceController.getSelectedLanguageLabel('File Expense')}" ajax="false" action="#{BHMaintenanceController.fileExpense()}"></p:commandButton>
</h:form>
如您所见,我已正确添加enctype
格式。我还添加了commons-io-2.4
和commons-fileupload-1.3.1
。我正在使用primefaces 5.1和JSF 2.0。
我的web.xml
<display-name>Panzer</display-name>
<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>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>start</param-value>
</context-param>
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto|native|commons</param-value>
</context-param>
<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>
</filter-mapping>
是否有版本问题,或者我做错了什么?