File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JasperException ,JspException & Cannot find FacesContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JasperException ,JspException & Cannot find FacesContext " Watch "JasperException ,JspException & Cannot find FacesContext " New topic

JasperException ,JspException & Cannot find FacesContext

S.Reddisekhar Reddy
Ranch Hand

Joined: Jan 05, 2012
Posts: 32
HI Team,
I added all jsf,jstl,commons related jars to the referenced library then also I am getting FacesContext cannot Find Exception
My JSP is like

<%@ taglib uri="" prefix="f" %>
<%@ taglib uri="" prefix="h" %>
<%@ taglib uri="" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<h:inputText value="#{viewItemsFB.catalogueNumber}"></h:inputText>
<h:commandButton action="#{viewItemsPB.getViewItems}">GET ITEMS</h:commandButton>

<f:view> is mandatory ,but when i add these tags
I am getting JasperException ,but in console i am getting Cannot find FacesContext
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 4

1: <%@ taglib uri="" prefix="f" %>
2: <%@ taglib uri="" prefix="h" %>
3: <%@ taglib uri="" prefix="c" %>
4: <f:view>

javax.servlet.jsp.JspException: Cannot find FacesContext
Balaji Manoharan Bm

Joined: Sep 22, 2013
Posts: 13
Think you are testing JSP directly using .jsp URL. JSF application must have FacesServet in web.xml and it should be mapped with *.jsf or *.xhtml.

After verifying this, replace your .jsp extention with .jsf and test.
for e.g., http://localhost:7001/demoapp/page/welcome.jsf
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

As of JSF version 2, JSP files are no longer allowed as View Templates. You must use "xhtml" files.

Raw JSPs could never be used with JSF, however. JSF is not an add-on tag library for JSP. And, in fact, in later versions of JSF, the View Template doesn't even compile to executable code the way that traditional JSPs do.

If you attempt to access FacesContext from a raw JSP or servlet, it will fail. The FacesContext is constructed and destroyed by the FacesServlet for each and every HTTP request/response cycle. It is not a durable object. So if the FacesServlet was not involved in the request processing, there will be no FacesContext to use.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: JasperException ,JspException & Cannot find FacesContext
It's not a secret anymore!