File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Jsf Error for simple jsf program in web application. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Jsf Error for simple jsf program in web application." Watch "Jsf Error for simple jsf program in web application." New topic
Author

Jsf Error for simple jsf program in web application.

Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 396
Hi,

I am running simple jsf program using the below URL:

http://localhost:8080/Project/converter.jsp

So getting this error:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find FacesContext
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find FacesContext
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.converter_jsp._jspService(converter_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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.converter_jsp._jspx_meth_f_005fview_005f0(converter_jsp.java:98)
org.apache.jsp.converter_jsp._jspService(converter_jsp.java:76)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.

then i tried to run web application by:

http://localhost:8080/Project/faces/converter.jsp

then i am getting Error:

javax.servlet.ServletException: Servlet execution threw an exception
root cause

java.lang.NoSuchMethodError: javax.faces.render.ResponseStateManager.getState(Ljavax/faces/context/FacesContext;Ljava/lang/String;)Ljava/lang/Object;
org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspStateManagerImpl.java:340)
org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(JspViewHandlerImpl.java:515)
com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:157)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)

So what is the possible cause for this error.

My web.xml file is as below

<web-app>

<display-name>JavaServer Faces Custom Components</display-name>
<description>
JavaServer Faces Custom Components
</description>

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>

<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
<description>
Set this flag to true if you want the JavaServer Faces
Reference Implementation to validate the XML in your
faces-config.xml resources against the DTD. Default
value is false.
</description>
</context-param>

<!--
PENDING: MapComponent and GraphComponent currently add
a default listener in their constructor, which can only
succeed if there is a FacesContext for the current request.
-->
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
<description>
Set this flag to true if you want the JavaServer Faces
Reference Implementation to verify that all of the application
objects you have configured (components, converters,
renderers, and validators) can be successfully created.
Default value is false.
</description>
</context-param>

<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>

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

<!-- Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>


could any one figure out ? please.
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 396
My build path lib for jsf are attached here :

There is some version conflict in jar file ?


[Thumbnail for JSf_error.jpg]

Sweta Ann
Greenhorn

Joined: Feb 04, 2010
Posts: 8
http://localhost:8080/Project/converter.jsp will show error since in web.xml

You have given the url-pattern
<url-pattern>*.faces</url-pattern>
<url-pattern>/faces/*</url-pattern>


The folowing 2 url should work for you based on your url-pattern
http://localhost:8080/Project/faces/converter.jsp
http://localhost:8080/Project/converter.faces


You can go through http://jsflessons.blogspot.com . It's good for beginners.
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 396
Hi,

I have tried both one but still getting the same error:

http://localhost:8080/Project/converter.faces
http://localhost:8080/Project/faces/converter.jsp

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception
root cause

java.lang.NoSuchMethodError: javax.faces.render.ResponseStateManager.getState(Ljavax/faces/context/FacesContext;Ljava/lang/String;)Ljava/lang/Object;
org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspStateManagerImpl.java:340)
org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(JspViewHandlerImpl.java:515)
com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:157)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
Sweta Ann
Greenhorn

Joined: Feb 04, 2010
Posts: 8
replace the web.xml by

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>

<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>


<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

</web-app>

Run your application

http://localhost:8080/Project/converter.jsf

This will work.


Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 396
i replaced the xml file but still get the same error:

javax.servlet.ServletException: Servlet execution threw an exception
root cause

java.lang.NoSuchMethodError: javax.faces.render.ResponseStateManager.getState(Ljavax/faces/context/FacesContext;Ljava/lang/String;)Ljava/lang/Object;
org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspStateManagerImpl.java:346)
org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(JspViewHandlerImpl.java:515)
com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:157)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.

and run the application:

http://localhost:8080/Project/converter.jsf
Sweta Ann
Greenhorn

Joined: Feb 04, 2010
Posts: 8


Where is your converter.jsp (folder)in the project?

are you using Eclipse + Tomcat?
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 396
Yes it is in default folder of the eclipse.

I am using Tomcat but not running it from eclipse.

I am running Tomcat from outside.



[Thumbnail for converter.jpg]

Sweta Ann
Greenhorn

Joined: Feb 04, 2010
Posts: 8


I have created a dynamic web project in eclipse.

It's seems like yours is a java project. I never tried running a java project on tomcat.

I strictly follow the steps mentioned in http://jsflessons.blogspot.com
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 396
No i am using via Import and Existing Project .

and one more thing if i run any jsp page or html page then it is working perfectly.

http://localhost:8080/index.jsp is working !
Prabhat Ranjan
Ranch Hand

Joined: Oct 04, 2006
Posts: 396
Problem solved !

Actually i was using both the jar files from myfaces and jsf-api.jar from sun ...that was the problem . There was conflict ion bet the two jar files version..

So i removed the myfaces jar files from the lib project build path.. but again i was getting the same error..you can see my attachment in build project jar files..No one figured out this..

One of my friend today told me you are using both the jar files from sun and myfaces so you are getting error.

Then i have seen in console tomcat still logging the myfaces daetils as error..then i have deleted the myfaces jar files from lib dir of my project..

Finally its working now.

Thanks everybody !
Venkateshkumar Singaravelu
Greenhorn

Joined: Mar 18, 2010
Posts: 6
While Iam trying to access the file directly,getting this Problem.Since I want to check as an example not configured Faces-config.xml..Can I run the File...Then How do i use RichFaces in Application
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Jsf Error for simple jsf program in web application.