JSF session timeout & Exception handling [duplicate]

纵饮孤独 提交于 2020-01-06 07:56:21

问题


Possible Duplicate:
JSF 1.2 Exception Handling

In the web.xml, i had the session-config as follows

<session-config>
  <session-timeout>2</session-timeout>
</session-config>   

and i also have a error-page defined as follows

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/sc00/ErrorPage.jsp</location>
 </error-page>

and when the application times-out i am unable to direct to the error page and it says

SRVE0260E: The server cannot use the error page specified for your application to handle the Original Exception printed below.


Original Exception: 
Error Message: javax.servlet.ServletException: /sc40/NewContract.facesNo saved         view      state could be found for the view identifier: /sc40/NewContract.faces
Error Code: 500
Target Servlet: Faces Servlet
Error Stack: 
javax.faces.application.ViewExpiredException: /sc40/NewContract.facesNo saved view     state could be found for the view identifier: /sc40/NewContract.faces 
 at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:128) 
 at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171) 
 at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189) 
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1147) 
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:722) 
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:449) 
 at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178) 
 at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1020) 
 at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3639) 
 at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304) 
 at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:950) 
 at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1659) 
 at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195) 
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452) 
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511) 
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305) 
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276) 
 at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214) 
 at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113) 
 at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) 
 at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) 
 at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) 
 at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) 
 at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) 
 at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) 
 at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) 
 at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1648) 




Error Page Exception: 
Error Message: java.lang.RuntimeException: FacesContext not found
Error Code: 0
Target Servlet: 
Error Stack: 
java.lang.RuntimeException: FacesContext not found 
 at javax.faces.webapp.UIComponentClassicTagBase.getFacesContext (UIComponentClassicTagBase.java:324) 
 at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:226) 
 at com.ibm._jsp._ErrorPage._jspx_meth_f_view_0(_ErrorPage.java:416) 
 at com.ibm._jsp._ErrorPage._jspService(_ErrorPage.java:103) 
 at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99) 
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:668) 
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1147) 
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:722) 
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:449) 
 at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178) 
 at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122) 
 at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:205) 
 at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1020) 
 at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:1382) 
 at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:191) 
 at com.ibm.ws.webcontainer.webapp.WebApp.sendError(WebApp.java:3143) 
 at com.ibm.ws.webcontainer.webapp.WebApp.handleException(WebApp.java:3669) 
 at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3650) 
 at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304) 
 at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:950) 
 at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1659) 
 at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195) 
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452) 
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511) 
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305) 
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276) 
 at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214) 
 at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113) 
 at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) 
 at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) 
 at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) 
 at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) 
 at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) 
 at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) 
 at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) 
 at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1648) 
                                                                                        and i am using jsf1.2

how can i direct the exception to errorpage.jsp, i don't want time-out exceptions to be handled by the jsf as i need to shut down the browser and restart-all over again. so please suggest me a way to handle this exception and i am using jsf1.2


回答1:


For some reason the above tag is not working in the web.xml, tried to figure out the reason, but couldn't.

To solve the problem i wrote a Listener class and registered the Listener class in "Facesconfig.xml" as follows

 <lifecycle>
<phase-listener>com.bcbsks.me.sc00.listeners.ErrorPageNavigationListener</phase-  listener>
</lifecycle> 

Here "ErrorPageNAvigationListener is the Listener class and the code in the Listener class is as follows.

public class ErrorPageNavigationListener implements PhaseListener{

/**
 * 
 */
private static final long serialVersionUID = 1L;

String HOME_PAGE = "../sc00/TimeOutPage.faces";

@Override
public void afterPhase(PhaseEvent event) {
    FacesContext facesContext = event.getFacesContext();
     if(facesContext.getViewRoot()==null){   
       try{   
           facesContext.getExternalContext().redirect(HOME_PAGE);                   
           facesContext.responseComplete(); 

         } catch (IOException e){   
           e.printStackTrace();   
       } 
     }
}

@Override
public void beforePhase(PhaseEvent event) {
    // TODO Auto-generated method stub

}

@Override
public PhaseId getPhaseId() {
    // TODO Auto-generated method stub
    return PhaseId.RESTORE_VIEW;

}   
}

The HOME_PAGE is the path to the error Page and it works fine for me.



来源:https://stackoverflow.com/questions/13297507/jsf-session-timeout-exception-handling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!