简体   繁体   中英

JSF 1.2 Exception Handling

I am working on exception handling in our Application. I used try catch blocks to catch the exceptions occured in my code and i also could handle the time out exceptions by writing a listener and registering the listener in "faces-config.xml".

But i am facing problems in catching unexpected errors like "NullPointerException" in constructor or error Codes 500, 400 etc.

i used the tags in the "web.xml"

<error-page>
      <exception-type>java.lang.Exception</exception-type>
      <location>/sc00/ErrorPage.jsp</location>
</error-page>

I tried many ways to handle the exceptions, can any one help me in finding out a solution. The error i am getting when i try to handle these exceptions is as follows.

I am using JSF 1.2 and the server is websphere 8

The Console shows the Following Exception.

com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0014E: Uncaught service() exception root cause Faces Servlet: javax.servlet.ServletException

E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [/sc00/ErrorPage.jsp] in application [MembershipEligibilityScreensEAR]. Exception created : [java.lang.RuntimeException: FacesContext not found

My Error Page is in /WebContent/sc00/ErrorPage.jsp, ErrorPage.jsp has no backing bean associated with it.

Many solutions asked me to look at the URL path of Faces Servlet, In My web.xml the servlet-mapping is a follows

 <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-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

all the paths in my faces-config.xml refer to /FolderName/JspName and they work fine and they work fine even in Navigation.xml.

How can i navigate it to ErrorPage.jsp, Is there any way so that i can write a listener to this kind of problem

Sorry for posting too many redundant questions, i am new to JSF and i don't know the rules of StackOverflow, I apologize for the problem i have caused.

any solution would be appreciated.

 java.lang.RuntimeException: FacesContext not found 

That will happen when you're requesting a JSP page containing JSF components through an URL which doesn't match the URL pattern of the FacesServlet (who is the one responsible for creating the FacesContext ).

You need to change the error page location to match the URL pattern of the FacesServlet as definited in web.xml . Based on your duplicate questions on the subject, this is among others *.faces , so setting the error page location as follows should do, exactly as I suggested in a comment on your first question on the subject.

<location>/sc00/ErrorPage.faces</location>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM