这可能是一个好方法:
1) 创建一个扩展 SavedRequestAwareAuthenticationSuccessHandler 的类
public class MyCustomSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws ServletException, IOException {
2) 将“成功处理程序”分配给安全筛选器:
<beans:bean id="myFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
<beans:property name="authenticationManager" ref="authenticationManager"/>
<beans:property name="authenticationFailureHandler" ref="failureHandler" />
<beans:property name="authenticationSuccessHandler" ref="successHandler" />
</beans:bean>
<beans:bean id="successHandler" class="yourPackage.MyCustomSuccessHandler" >
<beans:property name="defaultTargetUrl" value="/index.html" />
<beans:property name="alwaysUseDefaultTargetUrl" value="true"/>
</beans:bean>