Question

I'm new to Spring MVC.

I have URLs like this:

  • localhost:8080/spring-mvc-project-web-war/searchProjects
  • localhost:8080/spring-mvc-project-web-war/searchProjects/

The difference is the "/" at the end of each URL.

Both render a page with the same content. The content includes a search button, which will search through database and return a list of results. But the first URL always returns HTTP 404 - /spring-mvc-project-web-war/searchProjects and the second still works fine.

Can anyone explain this for me?

I know this is the problem of handler mapping but I don't really understand it clearly.

Was it helpful?

Solution

I think it's none of Spring HandlerMapping business.

when you click search button, the form http url posted depends on http base uri and your relative path(usually in action attribute)

"localhost:8080/spring-mvc-project-web-war/searchProjects" it's base uri is

localhost:8080/spring-mvc-project-web-war/

and "localhost:8080/spring-mvc-project-web-war/searchProjects/" base uri is

localhost:8080/spring-mvc-project-web-war/searchProjects/

In order to further understand,we can read Fielding's rfc document [Page 11]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top