0

在 WAS 门户中的 FileDownloadActionListener.processAction(FileDownloadActionListener.java:72) 下载文件时出现 NullPointerException

豆码:

 @ManagedBean(name = "briefsSearchViewBean")
    @SessionScoped
    public class BriefsSearchViewBean implements Serializable {
        private StreamedContent file;
    public StreamedContent getFile() {
            log.debug(" File Name " + new File("header.jpg").getAbsolutePath());
            String path = new File("header.jpg").getAbsolutePath();
            String contentType = FacesContext.getCurrentInstance()
                    .getExternalContext().getMimeType(path);
            log.debug(" contentType " + contentType );

            try {
                 InputStream is = new BufferedInputStream(
                           new FileInputStream(path));
                //file = new DefaultStreamedContent(new FileInputStream(path), contentType);
                file = new DefaultStreamedContent(is, contentType, "header.jpg");
                log.debug(" File Name " + file.getName());
                setFile(file);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                log.debug(" FileNotFoundException " + e);
                e.printStackTrace();
            }
            return file;
        }
    }

在调试语句中,我可以打印 contentType

xhtml

<p:commandButton value="Download" ajax="false">
    <p:fileDownload value="#{briefsSearchViewBean.file}" />
</p:commandButton>

error:

[6/24/13 9:09:17:387 EDT] 0000015d EventQueueMan E com.ibm.wps.pe.pc.waspc.event.EventQueueManager processEventLoop EJPPG1122E: An error occurred during portlet event processing.
                                 javax.portlet.PortletException
    at com.ibm.faces20.portlet.FacesPortlet.processAction(FacesPortlet.java:330)
    at briefssearchportlet.CaselookupPortlet.processAction(CaselookupPortlet.java:35)


Caused by: java.lang.NullPointerException
    at org.primefaces.component.filedownload.FileDownloadActionListener.processAction(FileDownloadActionListener.java:72)
4

0 回答 0