1、控制層沒有被spring掃描到,控制層沒有實例化,檢查自己的控制層是否被spring掃描到,檢查以下配置:<context:component-scan base-package=""/>
2、web.xml配置文件的<url-pattern>標籤配置成<url-pattern>/*</url-pattern>,正確的配置應該是<url-pattern>/</url-pattern>。學了structs之後再學spring mvc框架的 就會很容易犯這個錯誤。
3、使用的是註解實例化控制層,且web.xml的路徑配置爲<url-pattern>/</url-pattern>,卻沒有在spring的配置文件使用<mvc:annotation-driven />標籤,導致URL解析出錯,檢查是否加上<mvc:annotation-driven />。
當我們需要controller返回一個map的json對象時,可以設定<mvc:annotation-driven />,
同時設定<mvc:message-converters> 標籤,設定字符集和json處理類,例如:
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>