Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 登录Spring security后保持相同的URL_Java_Spring_Spring Security - Fatal编程技术网

Java 登录Spring security后保持相同的URL

Java 登录Spring security后保持相同的URL,java,spring,spring-security,Java,Spring,Spring Security,我想在登录后保持在同一页面,但spring强制您重定向到defaultSuccessUrl 我的代码是这样的 @Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .authorizeRequests() .antMatchers("/css/**","/fonts

我想在登录后保持在同一页面,但spring强制您重定向到
defaultSuccessUrl
我的代码是这样的

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable()
            .authorizeRequests()
            .antMatchers("/css/**","/fonts/**","/js/**","/app/**","/images/**","/partials/**").permitAll()
                .anyRequest()
                    .authenticated()
        .and()
            .formLogin()
                .loginPage("/login")
                    .defaultSuccessUrl("/index.html")
                    .failureUrl("/login?error=true")
                    .permitAll()
                    .and().logout().logoutSuccessUrl("/login?logout")
                    .and().exceptionHandling().accessDeniedPage("/pages/303.html");

    }
设置

始终使用默认的target=“true”


这将迫使spring security转到/index.html

我认为您应该添加一个身份验证成功处理程序

    @Override
protected void configure(HttpSecurity http) throws Exception {
   SavedRequestAwareAuthenticationSuccessHandler successHandler = new    SavedRequestAwareAuthenticationSuccessHandler();
   successHandler.setUseReferer(true);//redirect to the previous page
    http
        .csrf().disable()
        .authorizeRequests()
        .antMatchers("/css/**","/fonts/**","/js/**","/app/**","/images/**","/partials/**").permitAll()
            .anyRequest()
                .authenticated()
    .and()
        .formLogin()
            .loginPage("/login")
                .defaultSuccessUrl("/index.html")
                .failureUrl("/login?error=true")
                .permitAll()
                .successHandler(successHandler)//enable success handler
                .and().logout().logoutSuccessUrl("/login?logout")
                .and().exceptionHandling().accessDeniedPage("/pages/303.html");

}

禁止将其设置为true此链接可能会根据您的问题帮助您:)您是否尝试过
.loginPage(“/login”).defaultSuccessUrl(“/login”)
?您输入的URL是什么?它是单页应用程序吗?我可以注意到url中的“#”是的,我正在使用angularjs,所以当我单击url时,我会在同一页面中包含一个模板页面。你解决了吗