0

我正在尝试使用 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>

文件.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

我哪里错了?谢谢!

4

1 回答 1

0

您应该在标签之前添加web.xml :<filter-mapping>

<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>
于 2012-07-10T09:41:41.053 回答