Primefaces 5:验证码不适用于' javax.servlet.ServletException:表达式不能为空'

时间:2018-02-22 09:39:17

标签: primefaces captcha

我创建了一个简单的xhtml页面,其中包含以下代码(如Primefaces showcase):

    <body>
    <div>My test</div>

    <h:form>
        <p:messages showDetail="true"/>
        <p:captcha label="Captcha" />
    </h:form>

</body>

加载此页面,我会遇到以下例外情况:

exception

javax.servlet.ServletException: Expression cannot be null
root cause

javax.el.ELException: Expression cannot be null

我的范围是在表单中使用验证码组件,并检查用户是否通过按钮(提交)进行了检查。

这是完整的堆栈跟踪:

严重:错误渲染视图[/test.xhtml] javax.el.E​​LException:表达式不能为null     at com.sun.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:172)     在com.sun.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:237)     at com.sun.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:295)     at com.sun.el.E​​xpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:112)     在org.jboss.weld.util.el.ForwardingExpressionFactory.createValueExpression(ForwardingExpressionFactory.java:53)     在org.jboss.weld.el.WeldExpressionFactory.createValueExpression(WeldExpressionFactory.java:48)     at com.sun.faces.application.ApplicationImpl.evaluateExpressionGet(ApplicationImpl.java:446)     在javax.faces.application.ApplicationWrapper.evaluateExpressionGet(ApplicationWrapper.java:684)     在org.primefaces.component.captcha.CaptchaRenderer.getPublicKey(CaptchaRenderer.java:87)     在org.primefaces.component.captcha.CaptchaRenderer.encodeEnd(CaptchaRenderer.java:50)     在javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)     在javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)     在javax.faces.render.Renderer.encodeChildren(Renderer.java:176)     在javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)     在javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)     在javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)     在com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)     at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)     在javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)     at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)     在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)     在com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)     在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)     在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)     在org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)     在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)     在com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)     在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)     在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)     在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)     at com.sun.enterprise.v3.services.impl.ContainerMapper $ HttpHandlerCallable.call(ContainerMapper.java:459)     at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)     在org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)     在org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)     在org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)     在org.glassfish.grizzly.filterchain.ExecutorResolver $ 9.execute(ExecutorResolver.java:119)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)     在org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)     在org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)     在org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)     在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)     在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access $ 100(WorkerThreadIOStrategy.java:56)     在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy $ WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)     在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:565)     在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:545)     在java.lang.Thread.run(Thread.java:748) 信息:找到ExceptionQueuedEvent:true 严重:javax.el.E​​LException:Expression不能为null     at com.sun.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:172)     在com.sun.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:237)     at com.sun.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:295)     at com.sun.el.E​​xpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:112)     在org.jboss.weld.util.el.ForwardingExpressionFactory.createValueExpression(ForwardingExpressionFactory.java:53)     在org.jboss.weld.el.WeldExpressionFactory.createValueExpression(WeldExpressionFactory.java:48)     at com.sun.faces.application.ApplicationImpl.evaluateExpressionGet(ApplicationImpl.java:446)     在javax.faces.application.ApplicationWrapper.evaluateExpressionGet(ApplicationWrapper.java:684)     在org.primefaces.component.captcha.CaptchaRenderer.getPublicKey(CaptchaRenderer.java:87)     在org.primefaces.component.captcha.CaptchaRenderer.encodeEnd(CaptchaRenderer.java:50)     在javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)     在javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)     在javax.faces.render.Renderer.encodeChildren(Renderer.java:176)     在javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)     在javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)     在javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)     在com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)     at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)     在javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)     at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)     在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)     在com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)     在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)     在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)     在org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)     在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)     在com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)     在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)     在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)     在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)     at com.sun.enterprise.v3.services.impl.ContainerMapper $ HttpHandlerCallable.call(ContainerMapper.java:459)     at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)     在org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)     在org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)     在org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)     在org.glassfish.grizzly.filterchain.ExecutorResolver $ 9.execute(ExecutorResolver.java:119)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)     在org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)     在org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)     在org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)     在org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)     在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)     在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access $ 100(WorkerThreadIOStrategy.java:56)     在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy $ WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)     在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:565)     在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:545)     在java.lang.Thread.run(Thread.java:748) 警告:StandardWrapperValve [Faces Servlet]:用于servlet的Servlet.service()Faces Servlet抛出异常

1 个答案:

答案 0 :(得分:1)

您必须转到https://www.google.com/recaptcha/admin

获取私钥和​​公钥,然后使用

在web.xml中注册
<context-param>
        <param-name>primefaces.PUBLIC_CAPTCHA_KEY</param-name>
        <param-value>PUBLIC_KEY</param-value>
</context-param>

<context-param>
        <param-name>primefaces.PRIVATE_CAPTCHA_KEY</param-name>
        <param-value>PRIVATE_KEY</param-value>
</context-param>