i have ErrorPage.jsp in which i have
<h:messages styleClass="messageError" id="messages1"></h:messages>
when an Exception occurs in a backing beans constructor i catch it and i do the following
public constructorxxx throws Exception{
// code
// code
// code
catch(Exception e){
try{
LOG.error(e);
String customMessage = "An Unknown Error At " + e.getStackTrace()[0].toString() + "at" + message;
getFacesContext().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
customMessage, null));
throw new Exception();
}catch (IOException exception){
LOG.error(exception);
}
}
} // end of constructor
in my Web.xml i used the following tag.
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/ErrorPage.jsp</location>
when i do that i get the following errors
1) Uncaught service() exception root cause Faces Servlet: javax.servlet.ServletException
2) 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.
and in my page it displays as
SRVE0260E: The server cannot use the error page specified for your application to handle the Original Exception printed below.
Error Message: javax.servlet.ServletException
Error Code: 500
Target Servlet: Faces Servlet
Error Stack:
java.lang.Exception
// stack trace
Error Message: java.lang.RuntimeException: FacesContext not found
Error Code: 0
Target Servlet:
Error Stack:
java.lang.RuntimeException: FacesContext not found
Many people asked me to change the location of the ErrorPage.jsp as /sc00/ErrorPage.faces but it shows a broken link warning on my web.xml and the error is webpage cannot be displayed and programming error.
I am using jsf 1.2 and my “ErrorPage.jsp” doesn’t have a backing bean.
can anyone suggest me why the the Error.jsp is not being displayed?
Faces messages are request scoped, so they have the same lifetime as the current HTTP request-response cycle. However, you’re instructing the webbrowser to create a new HTTP request by sending a redirect. The faces messages are not there anymore in the new HTTP request.
You’d better just throw an exception and associate the particular error page with the particular exception by
<error-page>entry inweb.xml. The servletcontainer will automatically forward to the particular error page within the same request.E.g.
with
But given that your particular container and JSF impl/version apparently can’t forward to a JSF based error page (is it running in an infinite loop?), then your best bet is to remove all JSF components from the error page (otherwise you will get
RuntimeException: FacesContext not found) and make it a really plain vanilla JSP page with only HTML and JSTL.You should only put the message in the exception itself instead of adding as faces message.
Then, you can display it in the error page as follows:
You could even just let the exception go (i.e. just redeclare it as
throwsin action method.The servletcontainer will automatically log it anyway.