由于你使用的是Spring Security 3.0.x,因此可以按此处所述使用自定义sessionManagementFilter
com.icesoft.spring.security.JsfRedirectStrategy类在此处可用
如果你使用的是Spring Security 3.1.x,请进行以下更改
<beans:bean id="sessionManagementFilter" > <beans:constructor-arg name="securityContextRepository" ref="httpSessionSecurityContextRepository" /> <!-- this permits redirection to session timeout page from javascript/ajax or http --> <beans:property name="invalidSessionStrategy" ref="jsfRedirectStrategy" /></beans:bean><beans:bean id="jsfRedirectStrategy" > <beans:constructor-arg name="invalidSessionUrl" value="/general/logins/sessionExpired.jsf" /></beans:bean><beans:bean id="httpSessionSecurityContextRepository" />
对JSFRedirectStrategy类的唯一更改是前几行:
public class JsfRedirectStrategy implements InvalidSessionStrategy {protected final Log logger = LogFactory.getLog(getClass()); private String invalidSessionUrl;private boolean contextRelative;public JsfRedirectStrategy(String invalidSessionUrl){ this.invalidSessionUrl=invalidSessionUrl;}@Overridepublic void onInvalidSessionDetected(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String redirectUrl = calculateRedirectUrl(request.getContextPath(), invalidSessionUrl);这也适用于IE8。如果你有兴趣,也可以查看此博客,但是我从未尝试过这样做,因为上面的操作要容易得多。
仅供参考:如果你不使用Spring,则有很多方法可以执行此操作:Primefaces在其站点上执行此操作。 或者通过导入Omnifaces jar 链接更简单



