Java 在基于spring的web应用程序中处理会话过期事件

Java 在基于spring的web应用程序中处理会话过期事件,java,spring,spring-security,session-timeout,Java,Spring,Spring Security,Session Timeout,我在我的应用程序中使用了Spring安全特性,但我发现当会话过期时,所有请求ajax都返回页面login.jspnot重定向,在http响应中,它将所有html内容(我的webapp的登录页面)放入。 我在我的应用程序中使用了很多ajax请求,目标是返回某些错误代码,比如510,而不是登录页面 <session-management session-authentication-strategy-ref="example" /> 没有无效的会话url 我试图使无效的会话url=无

我在我的应用程序中使用了Spring安全特性,但我发现当会话过期时,所有请求ajax都返回页面login.jspnot重定向,在http响应中,它将所有html内容(我的webapp的登录页面)放入。 我在我的应用程序中使用了很多ajax请求,目标是返回某些错误代码,比如510,而不是登录页面

<session-management session-authentication-strategy-ref="example" /> 
没有无效的会话url 我试图使无效的会话url=无效。 非常感谢

使用自定义:

包com.example.spring.security //这里进口 公共类AjaxAwareAuthenticationEntryPoint 扩展LoginUrlAuthenticationEntryPoint{ 公共AjaxAwareAuthenticationEntryPointfinal字符串loginFormUrl{ superloginFormUrl; } @凌驾 公共无效开始最终HttpServletRequest请求、最终HttpServletResponse响应、最终身份验证异常authException 抛出IOException、ServletException{ 如果XMLHttpRequest.equalRequest.getHeaderX-Requested-With{ response.sendError403,禁止; }否则{ super.commerceRequest、response、authException; } } } 定义一个bean并将其用作入口点引用:

使用自定义:

包com.example.spring.security //这里进口 公共类AjaxAwareAuthenticationEntryPoint 扩展LoginUrlAuthenticationEntryPoint{ 公共AjaxAwareAuthenticationEntryPointfinal字符串loginFormUrl{ superloginFormUrl; } @凌驾 公共无效开始最终HttpServletRequest请求、最终HttpServletResponse响应、最终身份验证异常authException 抛出IOException、ServletException{ 如果XMLHttpRequest.equalRequest.getHeaderX-Requested-With{ response.sendError403,禁止; }否则{ super.commerceRequest、response、authException; } } } 定义一个bean并将其用作入口点引用: