账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    为什么我使用springMVC无法拦截根目录请求?总是使用默认的index.html
    63
    0

    spring拦截 localhost:8080/1可以拦截到我的chat页面,而拦截根目录就拦截不到,回去访问默认的index页面;

    控制台日志中有这么几行日志输出

    2018-06-04 15:46:03.601  INFO 15836 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/login] onto handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
    2018-06-04 15:46:03.601  INFO 15836 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
    2018-06-04 15:46:03.601  INFO 15836 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/1] onto handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
    2018-06-04 15:46:03.663  INFO 15836 --- [  restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
    
    

    springMVC的配置

    @Configuration
    public class WebMvcConfg implements WebMvcConfigurer {
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/login").setViewName("/login");
            registry.addViewController("/").setViewName("/chat");
            registry.addViewController("/1").setViewName("/chat");
        }
    }
    

    spring security的配置

    @Configuration
    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
    
            http.authorizeRequests()
                    .anyRequest()
                    .authenticated()
                    .and()
                    //开启默认登录页面
                    .formLogin()
                    //默认登录页面
                    .loginPage("/login")
                    //默认登录成功跳转页面
                    .defaultSuccessUrl("/")
                    .permitAll()
                    .and()
                    //设置注销
                    .logout()
                    .permitAll();
        }
       }
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部