Dispatcher servlet映射

时间:2012-08-22 10:11:09

标签: spring

我正在尝试使用spring-security

在所有配置之前

http://localhost:9090/app/login2.xhtml

请求,按照我的预期工作。

我添加了一个控制器:

@Controller
@RequestMapping("/auth")
public class LoginController {


 @RequestMapping(value = "/login", method = RequestMethod.GET)
 public String getLoginPage(@RequestParam(value="error", required=false) boolean error, 
   ModelMap model) {
return "login2.xhtnml";
}

}

我在web.xml中:

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                classpath:META-INF/spring-servlet.xml
        </param-value>
    </init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

当我打电话时使用此配置

http://localhost:9090/app/login2.xhtml

错误来了

 WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/app/login2.xhtml] in DispatcherServlet with name 'spring'

但是当我将配置映射更改为

<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>

http://localhost:9090/app/login2.xhtml按预期工作

http://localhost:9090/app/auth/login

没有错误,没有异常,没有重定向,我认为调度程序servlet无法知道这个请求。

http://localhost:9090/app/app/auth/login

一起使用
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/app/*</url-pattern>
    </servlet-mapping>

我的理解:

调度程序servlet使用"http://localhost:9090/"作为搜索login2.xhtml的基础 并使用"http://localhost:9090/app"获取/auth/login网址。

我不知道在哪里设置它,以及为什么它们不同。

1 个答案:

答案 0 :(得分:0)

您是否已将SpringSecurityFilterChain添加到web.xml?

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

如果容器启动(来自日志文件),你可以通过已注册的“请求绑定”吗?