3

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)

.......

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>

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

Ricardo
  • 31
  • 1
  • 1
  • 2
  • It looks like you are using the web.xml config for a JSF2 application (javax.faces.PROJECT_STAGE does not exist in JSF 1.2). Other than that the response from BalusC should cover your problem. – bogdan.mustiata May 15 '12 at 14:24
  • As a side recommendation I would suggest you to use facelets and not jsps to define your component tree. – bogdan.mustiata May 15 '12 at 14:25

1 Answers1

12

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

and not by

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

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555