错误如图:
引起这种错误的原因有一些,我的错误则是因为在静态文件夹下的原因。
如果要放在静态(static)文件夹下,需要在spring配置文件中添加上注解(<mvc:default-servlet-handler/>)和(<context:annotation-config></context:annotation-config>),如果有(<context:component-scan />),则不需要第二条注解。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
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-4.3.xsd">
<mvc:annotation-driven enable-matrix-variables="true"></mvc:annotation-driven>
<context:component-scan base-package="com.th.action"></context:component-scan>
<mvc:default-servlet-handler/>
<!-- <context:annotation-config></context:annotation-config> -->
配置文件如上,之后清理缓存,重启服务,再次打开相关网页就ok了