[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error : JavaServerFaces : Cannot find FacesContext

Posted on 2005-05-12
12
Medium Priority
?
12,814 Views
Last Modified: 2011-08-18
I get the following error when deploying web application with java server faces

exception :
javax.servlet.ServletException: Cannot find FacesContext
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:830)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:763)
      org.apache.jsp.index1_jsp._jspService(index1_jsp.java:93)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:105)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:336)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:251)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
      sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:324)
      org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
      java.security.AccessController.doPrivileged(Native Method)
      javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
      org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
      org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
      java.security.AccessController.doPrivileged(Native Method)
      java.security.AccessController.doPrivileged(Native Method)
      org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:675)
      org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:642)
      org.apache.jsp.index_jsp._jspService(index_jsp.java:46)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:105)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:336)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:251)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
      sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:324)
      org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
      java.security.AccessController.doPrivileged(Native Method)
      javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
      org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
      org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)

root cause
javax.servlet.jsp.JspException: Cannot find FacesContext
      javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:405)
      com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:105)
      org.apache.jsp.index1_jsp._jspx_meth_cr_view_0(index1_jsp.java:108)
      org.apache.jsp.index1_jsp._jspService(index1_jsp.java:83)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:105)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:336)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:251)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
      sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:324)
      org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
      java.security.AccessController.doPrivileged(Native Method)
      javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
      org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
      org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
      java.security.AccessController.doPrivileged(Native Method)
      java.security.AccessController.doPrivileged(Native Method)
      org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:675)
      org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:642)
      org.apache.jsp.index_jsp._jspService(index_jsp.java:46)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:105)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:336)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:251)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
      sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:324)
      org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
      java.security.AccessController.doPrivileged(Native Method)
      javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
      org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
      org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
====================================================================
----------------------------------------------------------------------------
                                     faces-config.xml
----------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC '-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN' ''>
<faces-config>
<navigation-rule>
    <from-view-id>index1.jsp</from-view-id>
    <navigation-case>
        <from-outcome>success</from-outcome>
        <to-view-id>index1.jsp</to-view-id>
    </navigation-case>
</navigation-rule>
<managed-bean>
    <managed-bean-name>Bean</managed-bean-name>
    <managed-bean-class>Package.BeanClass</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>    
</faces-config>
====================================================================
--------------------------------------------------------------------------------
                             index1.jsp
--------------------------------------------------------------------------------
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <%@taglib uri="http://java.sun.com/jsf/html" prefix="ht"%>
        <%@taglib uri="http://java.sun.com/jsf/core" prefix="cr"%>
    </head>
    <body>

<cr:view>
    <ht:form id="frm">
        <ht:inputText id="in" value="#{Bean.setMethod}" />
        <ht:commandButton value="Retrieve" action="success"/>
    </ht:form>
</cr:view>
    </body>
</html>
0
Comment
Question by:maXXXeE
  • 7
  • 4
12 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 13986540
Are you trying to view index.jsp directly?

Like:

    http://localhost:8080/index1.jsp

?

You can't do that...  You need to do:

    http://localhost:8080/index1.faces

or whatever you have decalerd index1.jsp to be known as...
0
 
LVL 35

Accepted Solution

by:
TimYates earned 2000 total points
ID: 13986566
0
 
LVL 7

Author Comment

by:maXXXeE
ID: 13987474
Hi TimYates
i am not using directly. i do a jsp forward from index.jsp to index1.jsp

i am checking out the link
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 35

Expert Comment

by:TimYates
ID: 13987548
>>  i do a jsp forward from index.jsp to index1.jsp

Try forwarding to index1.faces instead of index1.jsp (assuming your faces servlet is set up to use the ".faces" extension)

Tim
0
 
LVL 7

Author Comment

by:maXXXeE
ID: 13987725
Going by info on ur link, i did this
  <servlet-mapping>
    <servlet-name>FacesServlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>

but, any method by which i can keep the extension as jsp itself?

 <url-pattern>*</url-pattern> does not work, gives same exception as above
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13987773
>> but, any method by which i can keep the extension as jsp itself?

Not really...  JSP pages have to go through the JSP servlet (which is defined in tomcat/config/web.xml), wheras jsf pages have to go through the FacesServlet (as defined in your WEB-INF/web.xml)

ACTUALLY!  Thinking about it, you may be able to do:

 <servlet-mapping>
    <servlet-name>FacesServlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
 <servlet-mapping>
    <servlet-name>FacesServlet</servlet-name>
    <url-pattern>*.jsp</url-pattern>
  </servlet-mapping>

so that both jsp and jsf files go through the FacesServlet...

However I am not 100% sure this will work...

Hope it does :-)

Tim
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13987781
Apparently though, Struts won't work with duplicate mappings...

I have no idea if JSF will fail also :-(
0
 
LVL 7

Author Comment

by:maXXXeE
ID: 13987840
<servlet-mapping>
    <servlet-name>FacesServlet</servlet-name>
    <url-pattern>*.jsp</url-pattern>
  </servlet-mapping>

tried this already
does not work
0
 
LVL 7

Author Comment

by:maXXXeE
ID: 13987865
Thanx for the really fast help

However, if u find a way to the jsp extension problem, please do post it
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13987866
I think you're going to have to have

  index.jsp forwarding to index1.jsf

then, have index1.jsp as it is now, and

 <servlet-mapping>
    <servlet-name>FacesServlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>

in WEB-INF/web.xml

I reckon the file has to be a jsp, so that it can get parsed by the JSPServlet, but you have to reference it as .jsf so that the JSFServlet can do its magic first (before it then goes off to the jspservlet)

Tim
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13987882
:-)

Good luck with it all :-)

I will bookmark this Q incase I ever spot anything, but I reckon the way you have it now is the way it has to be done :-/

Good luck again!

Tim
0
 

Expert Comment

by:bostown03
ID: 14002088
I was porting an application from jsf/struts/jsf.  I was going out of my mind trying to get the answer, until finally, I tried prefixing my servlets with /faces like so:

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

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

For whatever its worth, hope it helps.

Take care.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If anyone asked you to network diagram of the internet, it was drawn in the form of a fluffy cloud which further became known as cloud computing. Popularly cloud computing is defined as workloads that run over the internet in a commercial provider’s…
In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question