JSF会话超时&异常处理

时间:2012-11-08 20:44:31

标签: jsf exception-handling

  

可能重复:
  JSF 1.2 Exception Handling

在web.xml中,我有如下的session-config

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

我还有一个错误页面定义如下

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

当应用程序超时时,我无法指向错误页面并且显示

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

如何将异常定向到errorpage.jsp,我不希望jsf处理超时异常,因为我需要关闭浏览器并重新启动 - 重新开始。所以请建议我一种处理此异常的方法,我正在使用jsf1.2

1 个答案:

答案 0 :(得分:0)

由于某些原因,上面的标记在web.xml中不起作用,试图弄清楚原因,但不能。

为了解决这个问题,我编写了一个Listener类,并在“Facesconfig.xml”中注册了Listener类,如下所示

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

此处“ErrorPageNAvigationListener是Listener类,Listener类中的代码如下所示。

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;

}   
}

HOME_PAGE是错误页面的路径,它对我来说很好。