我使用JSF与RichFacecs创建一个门户网站。我希望用户在登录页面重定向会话超时。 我试图扔在会话终结一个SecurityException /注销阶段如下
<error-page>
<exception-type>java.lang.SecurityException</exception-type>
<location>/Login.jsf</location>
</error-page>
但是,这不是为我工作。 这是处理这个正确的方式?
我使用JSF与RichFacecs创建一个门户网站。我希望用户在登录页面重定向会话超时。 我试图扔在会话终结一个SecurityException /注销阶段如下
<error-page>
<exception-type>java.lang.SecurityException</exception-type>
<location>/Login.jsf</location>
</error-page>
但是,这不是为我工作。 这是处理这个正确的方式?
这应该这样做:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/sessionExpired.jsf</location>
</error-page>
你应该把超时在web.xml,如图所示,在这个线程注册超时过滤器: 自动注销在JSF应用程序在阿贾克斯的情况下,你的重定向,必须这样做:
String facesRequestHeader = httpServletRequest
.getHeader( "Faces-Request" );
boolean isAjaxRequest = facesRequestHeader != null
&& facesRequestHeader.equals( "partial/ajax" );
if( isAjaxRequest )
{
String url = MessageFormat.format( "{0}://{1}:{2,number,####0}{3}",
request.getScheme(), request.getServerName(),
request.getServerPort(), timeoutPath );
PrintWriter pw = response.getWriter();
pw.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" );
pw.println( "<partial-response><redirect url=\"" + url
+ "\"></redirect></partial-response>" );
pw.flush(););
}
else
{
httpServletResponse.sendRedirect( timeoutPath );
}
解决的办法是使用RichFaces自己的session expired event
。
此添加到页面容易失效:
<a4j:region>
<script language="javascript">
A4J.AJAX.onExpired = function(loc, expiredMsg){
alert('expired!');
window.location = "/login.jsf";
}
</script>
</a4j:region>
更多信息可在RichFaces的文档中找到: http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/ArchitectureOverview.html#SessionExpiredHandling
我有一些问题,当我会话过期后进行A4J请求。 我把这个
<context-param>
<param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
<param-value>true</param-value>
</context-param>
在我的web.xml,对我来说,解决了这个问题。
另一个解决方案是创建扩展的ViewHandler CustomViewHandler并重写restoreView方法
@Override
public UIViewRoot restoreView(FacesContext facesContext, String viewId) {
/**
* {@link javax.faces.application.ViewExpiredException}. This happens only when we try to logout from timed out pages.
*/
UIViewRoot root = null;
root = parent.restoreView(facesContext, viewId);
if(root == null) {
root = createView(facesContext, viewId);
}
return root;
}
然后,你需要把它添加到您的faces-config.xml中
<view-handler>com.demo.CustomViewHandler</view-handler>
这将阻止你获得ViewExpiredException的