且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JSF会话超时&异常处理

更新时间:2023-12-04 18:37:40

出于某种原因,上述标记不是

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

为解决该问题,我编写了一个Listener类,并在 Facesconfig.xml,如下所示:

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> 

此处 ErrorPageNAvigationListener是Listener类,并且Listener类中的代码如下。

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;

}   
}

HOME_PAGE是指向错误页面,对我来说很好。

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