结合自己犯的错,加上网上其他人的答案,总结出了四种办法:
1、在你的springmvc.xml(你的不一定是这个名字,但是都是这个配置文件)中添加扫描包
<context:component-scan base-package="com.***.springmvc.controller"/>
2、web.xml配置文件的url-pattern需要设置成*.action,如果不行,就设置为“/”
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 这个是diaspatchServlet的初始化条件 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
3、全部采用默认的,在springmvc.xml中增加<mvc:default-servlet-handler/>(一般不太推荐这个)
4、如果采用注解模式(我用的就是注解)几个地方的注解不能省略
//@Controller
public class ItemController {
@RequestMapping("/itemList.action")
public ModelAndView itemList(){