-1

我已经尝试了 BalusC 从链接JSF 2.0 文件上传中给出的代码,但我遇到了错误。似乎选择的文件没有被传递给 UplaodFile 对象或提交方法没有被调用。

点击提交按钮后报错:

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 尝试了代码

4

1 回答 1

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.

于 2013-08-19T12:59:26.450 回答