java.lang.RuntimeException:找不到FacesContext(JSF 1.2+;Primefaces+;Tomcat 6)
在Tomcat 6上运行我的项目时,我遇到了这个问题:java.lang.RuntimeException:找不到FacesContext(JSF 1.2+;Primefaces+;Tomcat 6),jsf,tomcat,Jsf,Tomcat,在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)
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:
<?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>
javax.faces.PROJECT_阶段
发展
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
*.面孔
资源Servlet
org.primefaces.resource.ResourceServlet
资源Servlet
/素数资源/*
index.jsp
知道发生了什么吗?我需要在pom.xml或类似的地方配置依赖项吗?感谢您的帮助。由
FacesServlet
创建FacesContext
。此异常表示FacesServlet
未完成其工作。您已将FacesServlet
配置为侦听与模式*.faces
匹配的URL。因此,您需要确保请求URL(出现在浏览器地址栏中的URL)与此URL匹配,以便调用它
换句话说,您需要在
http://localhost:8080/context/Contato.faces
而不是
http://localhost:8080/context/Contato.jsp
与具体问题无关,我不确定“PrimeFaces”在你的问题标题中做了什么,但我只是想警告PrimeFaces根本不支持JSP。它只支持其后续Facelets(XHTML)。在JSP文件而不是Facelets文件中为Facelets使用PrimeFaces标记只会导致它们被解释为普通HTML。看起来您正在为JSF2应用程序使用web.xml配置(JSF 1.2中不存在javax.faces.PROJECT_STAGE)。除此之外,BalusC的回复应该涵盖您的问题。作为附带建议,我建议您使用facelets而不是JSP来定义组件树。