【问题标题】:defaultSuccessUrl not correctly rendering the html pagedefaultSuccessUrl 未正确呈现 html 页面
【发布时间】:2017-10-16 21:52:56
【问题描述】:

我正在尝试使用 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 状态

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

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;
    })
};

有人知道为什么吗?

【问题讨论】:

  • 如何发布登录表单?阿贾克斯?
  • @chaoluo 我在前端使用 AngularJS。我刚刚使用发布请求服务更新了我的第一条评论

标签: angularjs spring spring-security


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-10-09
    • 2023-04-09
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2020-01-09
    • 2012-03-05
    相关资源
    最近更新 更多