What am I missing here? Why is this not simply working? If I use the same url-pattern to map to a plain Servlet instance, it works fine and I reach the doGet method, but with Spring MVC I seem to missing some particular black magic to get this to work.推荐答案您可以在web.xml文件中声明欢迎页面,而不是映射到/:Instead of mapping to / you can declare a welcome page in your web.xml file:<welcome-file-list> <welcome-file>welcome.htm</welcome-file></welcome-file-list>,因此您的/路径将被处理为/welcome.htm,然后,如果您的控制器已正确映射到/welcome.htm,它将处理/,就好像它是/welcome.htm请求一样,而无需更改其他配置. so your / path will be processed as /welcome.htm and then if your controller is correctly mapped to /welcome.htm it will process / as if it was a /welcome.htm request, without making changes to other configuration. 这篇关于在Spring MVC中映射/(根URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-25 18:46