在webapp下新建一个index.html,但是输入http://localhost:8080/index.html报404错误,无法访问,而新建项目时自动生成的index.jsp可以访问。
控制台报错信息如下:
警告 [http-nio-8080-exec-61] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/index.html] in DispatcherServlet with name 'springMVC'说是url处理器没有映射,原因是在web.xml中,将所有url拦截下来,但是没有给对应的dispatcherServlet处理,因此访问不到
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>将拦截路径修改成别的路径,不要拦截到index.html就好了。例如将拦截路径修改如下:
<servlet-name>springMVC</servlet-name> <url-pattern>/Index/HelloWorld</url-pattern>

本文介绍了解决在Spring MVC框架下,使用http://localhost:8080/index.html时出现404错误的方法。通过调整web.xml中的URL拦截设置,确保静态HTML文件能够被正确访问。
6138





