defaultSuccessUrl无法正确呈现html页面

时间:2017-05-17 12:23:04

标签: angularjs spring spring-security

我正在尝试使用Spring安全性和AngularJS设置defaultSuccessUrl,但是在成功登录后,html页面将加载到网络中但不会显示。 这是我的安全配置

   http
      .authorizeRequests()
          .anyRequest().authenticated().and()
      .formLogin()
          .loginPage("/")
          .loginProcessingUrl("/")
          .successHandler(this.authSuccess)
          .failureHandler(this.authFailure).permitAll()
          .defaultSuccessUrl("/app/components/hello.jsp", true);


    http
        .authorizeRequests()
            .anyRequest().authenticated().and()
        .logout()
             .logoutSuccessHandler(this.logoutSuccess)
             .deleteCookies("JSESSIONID")
             .invalidateHttpSession(false).permitAll();

但是当我检查网络时,我可以看到登录的发布请求被重定向为302状态代码,Hello.jsp加载了200状态enter image description here

但是我仍然显示登录页面而不是hello.jsp页面。 用于登录的角度服务:

this_.login = function(data) {
    return $http.post(_contextPath + '/',
            "username=" + data.username + "&password=" + data.password, {
                headers : {
                    'Content-Type' : 'application/x-www-form-urlencoded'
                }
            }).success(function(response) {
        return response.status;
    }).error(function(response) {
        return response.status;
    })
};

任何人都知道为什么?

1 个答案:

答案 0 :(得分:0)

您正在使用ajax发布登录表单,因此页面无法重定向到成功网址,您可以返回默认网址,然后重定向到前端的网址。比如this