java.lang.RuntimeException:找不到FacesContext(JSF 1.2 + Primefaces + Tomcat 6) [英] java.lang.RuntimeException: Cannot find FacesContext (JSF 1.2 + Primefaces + Tomcat 6)

查看:43
本文介绍了java.lang.RuntimeException:找不到FacesContext(JSF 1.2 + Primefaces + Tomcat 6)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Tomcat 6上运行项目时遇到此问题:

Im having this problem when trying to run my project at Tomcat 6:

SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.RuntimeException: Cannot find FacesContext
        at javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:2122)
        at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1933)
        at org.apache.jsp.Contato_jsp._jspx_meth_f_005fview_005f0(Contato_jsp.java:125)
        at org.apache.jsp.Contato_jsp._jspService(Contato_jsp.java:102)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)

.......

我已经将jsf-impl.jar,jsf-api.jar和jstl-1.2.jar添加到类路径中.还有其他库吗?在下面的代码中,您可以检查web.xml:

I have already added the jsf-impl.jar, jsf-api.jar and jstl-1.2.jar to the classpath. Any other lib is necessary? In the following u can check the web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Resource Servlet</servlet-name>
        <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Resource Servlet</servlet-name>
        <url-pattern>/primefaces_resource/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>


</web-app>

有什么想法吗?我需要在pom.xml或类似的东西上配置依赖项吗?感谢您的帮助.

Any idea of what is happening? Do I need to configure dependencies at pom.xml or something like that? Thanks for helping.

推荐答案

FacesContextFacesServlet创建.此异常意味着FacesServlet尚未完成其工作.您已配置FacesServlet以侦听与模式*.faces匹配的URL.因此,您需要确保请求URL(出现在浏览器地址栏中的请求URL)与该URL匹配,以便被调用.

The FacesContext is created by the FacesServlet. This exception means that the FacesServlet hasn't done its job. You have configured the FacesServlet to listen on URLs matching pattern *.faces. Thus you need to ensure that the request URL (the one which appears in browser address bar) matches this URL so that it get invoked.

换句话说,您需要打开页面

In other words, you need to open the page by

http://localhost:8080/context/Contato.faces

不是作者

http://localhost:8080/context/Contato.jsp


无关,与具体问题无关,我不确定您的问题标题中的"PrimeFaces"在做什么,但我只是想警告PrimeFaces根本不支持JSP.它仅支持其后继Facelets(XHTML).在JSP文件而不是Facelets文件中为Facelets使用PrimeFaces标记只会导致将它们解释为普通的HTML.


Unrelated to the concrete problem, I'm not sure what "PrimeFaces" is doing in your question title, but I just wanted to warn that PrimeFaces doesn't support JSP at all. It supports only its successor Facelets (XHTML). Using PrimeFaces tags for Facelets in a JSP file instead of a Facelets file would only cause them being interpreted as plain vanilla HTML.

这篇关于java.lang.RuntimeException:找不到FacesContext(JSF 1.2 + Primefaces + Tomcat 6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆