Spring 安全不重定向到主页

Spring security does not redirect to home page

您好,当我键入基本 servlet 的 url 时,我遇到了将请求重定向到主页的问题。

当我输入时

http://localhost:8080/servlet/home

这很好用,但是当我输入时

http://localhost:8080/servlet/

我想查看主页,但系统将其重定向到拒绝访问的页面。

控制器

@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home() {
    return "home";
}

@RequestMapping(value = "/", method = RequestMethod.GET)
public String redirectHome() {
    return "home";
}

Spring 安全

<access-denied-handler error-page="/denied" />
<intercept-url pattern="/home" access="permitAll" />  
<intercept-url pattern="/" access="permitAll" />   
...

检查您的 web.xml 文件以获取欢迎文件。

     <welcome-file-list>
        <welcome-file>[your page]</welcome-file>
    </welcome-file-list>