我已经尝试过BalusC从链接JSF 2.0 File upload给出的代码,但是我得到了以下错误。看来所选的文件没有传递给UplaodFile对象,也没有调用submit方法。
点击提交按钮后出错:
javax.faces.el.EvaluationException: java.lang.NullPointerException at
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) at
javax.faces.component.UICommand.broadcast(UICommand.java:315) at
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) at
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) at
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542) at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at
com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849) at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) at
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at
com.sun.grizzly.ContextTask.run(ContextTask.java:71) at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at
java.lang.Thread.run(Thread.java:662) Caused by: java.lang.NullPointerException at
suraj.Bean.submit(Bean.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at
java.lang.reflect.Method.invoke(Method.java:597) at
com.sun.el.parser.AstValue.invoke(AstValue.java:254) at
com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302) at
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) at
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) ... 32 more
------------------------------------------------------------------------
一旦将对象保存在UploadFile对象中,请建议以及如何在HTTP服务器中上传文件。
使用的配置:尝试使用Netbeans和Eclipse(使用Tomcat 6.0)JSF 2.0
的代码答案 0 :(得分:0)
您至少没有根据说明正确注册ExtensionsFilter
。此过滤器负责解析上载的过滤器,但在堆栈跟踪中完全丢失。我希望在FacesServlet#service()
之前的某个地方看到它如此:
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:XXX)
...
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:XXX)
也许您需要阅读说明文本而不是盲目地复制代码?它必须映射到<servlet-name>
的确切FacesServlet
。