介绍
小编给大家分享一下springmvc报错404怎么办,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获、下面让我们一起去了解一下吧!
编程环境:win10x64 + eclipse + Tomcat8.5
文件结构:
主要代码:
。xml
& lt; ? xml version=?.0“,编码=癠TF-8" ?比; & lt; web-app  xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance", xmlns=癶ttp://xmlns.jcp.org/xml/ns/javaee", xsi: schemaLocation=? http://xmlns.jcp.org/xml/ns/javaee , http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd", id=癢ebApp_ID", version=?.1“比; & lt; display-name> MyWeb & lt; welcome-file-list> & lt; welcome-file> index.html & lt; welcome-file> index.htm & lt; welcome-file> index.jsp & lt; welcome-file> default.html & lt; welcome-file> default.htm & lt; welcome-file> default.jsp & lt;/welcome-file-list> 春天& lt; !——,加载配置文件,——比; & lt; context-param> & lt; param-name> contextConfigLocation & lt; param-value>类路径:springMvc.xml & lt;/context-param> & lt; !——,春天监听,——比; & lt; listener> & lt; listener-class> org.springframework.web.context.ContextLoaderListener & lt;/listener> & lt; !——,配置springMvc ——比; & lt; servlet> & lt; servlet-name> springMvc & lt; servlet-class> org.springframework.web.servlet.DispatcherServlet & lt; init-param> & lt; param-name> contextConfigLocation & lt; param-value>类路径:springMvc.xml & lt;/init-param> & lt; load-on-startup> 1 & lt;/load-on-startup> & lt; async-supported> true & lt;/servlet> & lt; servlet-mapping> & lt; servlet-name> springMvc & lt; url-pattern>/& lt;/url-pattern> & lt;/servlet-mapping> & lt;/web-app>
HelloController。java
package com.hello; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @ controller public class  HelloController { @RequestMapping (“/success") public String  helloWorld (), { System.out.println(“拦截“); return “success"; } }
springMvc。xml
& lt; ? xml version=?.0“,编码=癠TF-8" ?比; http://www.springframework.org/schema/beans" & lt; beans  xmlns=?; xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance" xmlns:上下文=癶ttp://www.springframework.org/schema/context" xmlns: mvc=癶ttp://www.springframework.org/schema/mvc" xsi: schemaLocation=? http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context , http://www.springframework.org/schema/context/spring-context.xsd ,http://www.springframework.org/schema/mvc , http://www.springframework.org/schema/mvc/spring-mvc.xsd “的在 & lt; mvc: annotation-driven /比; & lt;上下文:component-scan 基础包=癱om.hello"/比; & lt; !——,处理静态资源,——比; & lt; mvc: default-servlet-handler/比; & lt; !——,配置视图解析器,——比; & lt;豆 类=皁rg.springframework.web.servlet.view.InternalResourceViewResolver"比; & lt; property name=皃refix", value=https://www.yisu.com/zixun/"/web - inf/jsp/"/> <属性名="后缀" value=" . jsp "/> 豆> 豆>
调试图: