我正在尝试使用RichFaces上传文件,但它不会上传文件。
我所做的是:
file.jsp
<h:form>
<rich:panel header="FileUpload demostration">
<rich:fileUpload
fileUploadListener="#{fileUploadBean.listener}"
id="upload"
maxFilesQuantity="10"
immediateUpload="true"
/>
</rich:panel>
</h:form>
file.java
public class FileUploadBean {
private List<String> uploadedList;
private UploadItem item;
public FileUploadBean(){
this.uploadedList = new LinkedList<String>();
}
public void listener(UploadEvent event) throws IOException {
this.setItem(event.getUploadItem());
getUploadedList().add(this.getItem().getFileName());
System.out.println("Elements in the list: ");
for(String name : this.getUploadedList()){
System.out.println(name);
}
}
/**
* @return the uploadedList
*/
public List<String> getUploadedList() {
return uploadedList;
}
/**
* @param uploadedList the uploadedList to set
*/
public void setUploadedList(List<String> uploadedList) {
this.uploadedList = uploadedList;
}
/**
* @return the item
*/
public UploadItem getItem() {
return item;
}
/**
* @param item the item to set
*/
public void setItem(UploadItem item) {
this.item = item;
}
} 我在web.xml中添加了这个:
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
当我运行它时,它会给我jsp页面,我可以选择图像,但是当我执行uload时它会显示transfer error occured
并发生在此行:'#{fileUploadBean.listener}' java.lang.NullPointerException
我哪里出错了? 谢谢!
答案 0 :(得分:0)
您应该在<filter-mapping>
标记之前添加 web.xml :
<filter>
<display-name>Ajax4jsf Filter</display-name>
<filter-name>ajax4jsf</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
<init-param>
<param-name>createTempFiles</param-name>
<param-value>false</param-value>
</init-param>
</filter>