maXXXeE
asked on
Error : JavaServerFaces : Cannot find FacesContext
I get the following error when deploying web application with java server faces
exception :
javax.servlet.ServletExcep tion: Cannot find FacesContext
org.apache.jasper.runtime. PageContex tImpl.doHa ndlePageEx ception(Pa geContextI mpl.java:8 30)
org.apache.jasper.runtime. PageContex tImpl.hand lePageExce ption(Page ContextImp l.java:763 )
org.apache.jsp.index1_jsp. _jspServic e(index1_j sp.java:93 )
org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:105 )
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 860)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 36)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:301)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:251)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 860)
sun.reflect.GeneratedMetho dAccessor6 4.invoke(U nknown Source)
sun.reflect.DelegatingMeth odAccessor Impl.invok e(Delegati ngMethodAc cessorImpl .java:25)
java.lang.reflect.Method.i nvoke(Meth od.java:32 4)
org.apache.catalina.securi ty.Securit yUtil$1.ru n(Security Util.java: 249)
java.security.AccessContro ller.doPri vileged(Na tive Method)
javax.security.auth.Subjec t.doAsPriv ileged(Sub ject.java: 500)
org.apache.catalina.securi ty.Securit yUtil.exec ute(Securi tyUtil.jav a:282)
org.apache.catalina.securi ty.Securit yUtil.doAs Privilege( SecurityUt il.java:16 5)
java.security.AccessContro ller.doPri vileged(Na tive Method)
java.security.AccessContro ller.doPri vileged(Na tive Method)
org.apache.jasper.runtime. PageContex tImpl.doFo rward(Page ContextImp l.java:675 )
org.apache.jasper.runtime. PageContex tImpl.forw ard(PageCo ntextImpl. java:642)
org.apache.jsp.index_jsp._ jspService (index_jsp .java:46)
org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:105 )
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 860)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 36)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:301)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:251)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 860)
sun.reflect.GeneratedMetho dAccessor6 4.invoke(U nknown Source)
sun.reflect.DelegatingMeth odAccessor Impl.invok e(Delegati ngMethodAc cessorImpl .java:25)
java.lang.reflect.Method.i nvoke(Meth od.java:32 4)
org.apache.catalina.securi ty.Securit yUtil$1.ru n(Security Util.java: 249)
java.security.AccessContro ller.doPri vileged(Na tive Method)
javax.security.auth.Subjec t.doAsPriv ileged(Sub ject.java: 500)
org.apache.catalina.securi ty.Securit yUtil.exec ute(Securi tyUtil.jav a:282)
org.apache.catalina.securi ty.Securit yUtil.doAs Privilege( SecurityUt il.java:16 5)
root cause
javax.servlet.jsp.JspExcep tion: Cannot find FacesContext
javax.faces.webapp.UICompo nentTag.do StartTag(U IComponent Tag.java:4 05)
com.sun.faces.taglib.jsf_c ore.ViewTa g.doStartT ag(ViewTag .java:105)
org.apache.jsp.index1_jsp. _jspx_meth _cr_view_0 (index1_js p.java:108 )
org.apache.jsp.index1_jsp. _jspServic e(index1_j sp.java:83 )
org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:105 )
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 860)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 36)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:301)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:251)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 860)
sun.reflect.GeneratedMetho dAccessor6 4.invoke(U nknown Source)
sun.reflect.DelegatingMeth odAccessor Impl.invok e(Delegati ngMethodAc cessorImpl .java:25)
java.lang.reflect.Method.i nvoke(Meth od.java:32 4)
org.apache.catalina.securi ty.Securit yUtil$1.ru n(Security Util.java: 249)
java.security.AccessContro ller.doPri vileged(Na tive Method)
javax.security.auth.Subjec t.doAsPriv ileged(Sub ject.java: 500)
org.apache.catalina.securi ty.Securit yUtil.exec ute(Securi tyUtil.jav a:282)
org.apache.catalina.securi ty.Securit yUtil.doAs Privilege( SecurityUt il.java:16 5)
java.security.AccessContro ller.doPri vileged(Na tive Method)
java.security.AccessContro ller.doPri vileged(Na tive Method)
org.apache.jasper.runtime. PageContex tImpl.doFo rward(Page ContextImp l.java:675 )
org.apache.jasper.runtime. PageContex tImpl.forw ard(PageCo ntextImpl. java:642)
org.apache.jsp.index_jsp._ jspService (index_jsp .java:46)
org.apache.jasper.runtime. HttpJspBas e.service( HttpJspBas e.java:105 )
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 860)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:3 36)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:301)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:251)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 860)
sun.reflect.GeneratedMetho dAccessor6 4.invoke(U nknown Source)
sun.reflect.DelegatingMeth odAccessor Impl.invok e(Delegati ngMethodAc cessorImpl .java:25)
java.lang.reflect.Method.i nvoke(Meth od.java:32 4)
org.apache.catalina.securi ty.Securit yUtil$1.ru n(Security Util.java: 249)
java.security.AccessContro ller.doPri vileged(Na tive Method)
javax.security.auth.Subjec t.doAsPriv ileged(Sub ject.java: 500)
org.apache.catalina.securi ty.Securit yUtil.exec ute(Securi tyUtil.jav a:282)
org.apache.catalina.securi ty.Securit yUtil.doAs Privilege( SecurityUt il.java:16 5)
========================== ========== ========== ========== ========== ==
-------------------------- ---------- ---------- ---------- ---------- ----------
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</fro m-outcome>
<to-view-id>index1.jsp</to -view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>Bean</m anaged-bea n-name>
<managed-bean-class>Packag e.BeanClas s</managed -bean-clas s>
<managed-bean-scope>sessio n</managed -bean-scop e>
</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>
exception :
javax.servlet.ServletExcep
org.apache.jasper.runtime.
org.apache.jasper.runtime.
org.apache.jsp.index1_jsp.
org.apache.jasper.runtime.
javax.servlet.http.HttpSer
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
sun.reflect.GeneratedMetho
sun.reflect.DelegatingMeth
java.lang.reflect.Method.i
org.apache.catalina.securi
java.security.AccessContro
javax.security.auth.Subjec
org.apache.catalina.securi
org.apache.catalina.securi
java.security.AccessContro
java.security.AccessContro
org.apache.jasper.runtime.
org.apache.jasper.runtime.
org.apache.jsp.index_jsp._
org.apache.jasper.runtime.
javax.servlet.http.HttpSer
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
sun.reflect.GeneratedMetho
sun.reflect.DelegatingMeth
java.lang.reflect.Method.i
org.apache.catalina.securi
java.security.AccessContro
javax.security.auth.Subjec
org.apache.catalina.securi
org.apache.catalina.securi
root cause
javax.servlet.jsp.JspExcep
javax.faces.webapp.UICompo
com.sun.faces.taglib.jsf_c
org.apache.jsp.index1_jsp.
org.apache.jsp.index1_jsp.
org.apache.jasper.runtime.
javax.servlet.http.HttpSer
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
sun.reflect.GeneratedMetho
sun.reflect.DelegatingMeth
java.lang.reflect.Method.i
org.apache.catalina.securi
java.security.AccessContro
javax.security.auth.Subjec
org.apache.catalina.securi
org.apache.catalina.securi
java.security.AccessContro
java.security.AccessContro
org.apache.jasper.runtime.
org.apache.jasper.runtime.
org.apache.jsp.index_jsp._
org.apache.jasper.runtime.
javax.servlet.http.HttpSer
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
sun.reflect.GeneratedMetho
sun.reflect.DelegatingMeth
java.lang.reflect.Method.i
org.apache.catalina.securi
java.security.AccessContro
javax.security.auth.Subjec
org.apache.catalina.securi
org.apache.catalina.securi
==========================
--------------------------
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</
<navigation-case>
<from-outcome>success</fro
<to-view-id>index1.jsp</to
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>Bean</m
<managed-bean-class>Packag
<managed-bean-scope>sessio
</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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi TimYates
i am not using directly. i do a jsp forward from index.jsp to index1.jsp
i am checking out the link
i am not using directly. i do a jsp forward from index.jsp to index1.jsp
i am checking out the link
>> 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
Try forwarding to index1.faces instead of index1.jsp (assuming your faces servlet is set up to use the ".faces" extension)
Tim
ASKER
Going by info on ur link, i did this
<servlet-mapping>
<servlet-name>FacesServlet </servlet- name>
<url-pattern>*.jsf</url-pa ttern>
</servlet-mapping>
but, any method by which i can keep the extension as jsp itself?
<url-pattern>*</url-patter n> does not work, gives same exception as above
<servlet-mapping>
<servlet-name>FacesServlet
<url-pattern>*.jsf</url-pa
</servlet-mapping>
but, any method by which i can keep the extension as jsp itself?
<url-pattern>*</url-patter
>> 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-pa ttern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet </servlet- name>
<url-pattern>*.jsp</url-pa ttern>
</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
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
<url-pattern>*.jsf</url-pa
</servlet-mapping>
<servlet-mapping>
<servlet-name>FacesServlet
<url-pattern>*.jsp</url-pa
</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
Apparently though, Struts won't work with duplicate mappings...
I have no idea if JSF will fail also :-(
I have no idea if JSF will fail also :-(
ASKER
<servlet-mapping>
<servlet-name>FacesServlet </servlet- name>
<url-pattern>*.jsp</url-pa ttern>
</servlet-mapping>
tried this already
does not work
<servlet-name>FacesServlet
<url-pattern>*.jsp</url-pa
</servlet-mapping>
tried this already
does not work
ASKER
Thanx for the really fast help
However, if u find a way to the jsp extension problem, please do post it
However, if u find a way to the jsp extension problem, please do post it
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-pa ttern>
</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
index.jsp forwarding to index1.jsf
then, have index1.jsp as it is now, and
<servlet-mapping>
<servlet-name>FacesServlet
<url-pattern>*.jsf</url-pa
</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
:-)
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
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
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</welco me-file>
</welcome-file-list>
For whatever its worth, hope it helps.
Take care.
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.
</welcome-file-list>
For whatever its worth, hope it helps.
Take care.
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...