No mapping found for HTTP request with URI [...] in DispatcherServlet with name ‘DispatcherServlet‘
程序员文章站
2022-07-15 13:25:47
...
该错误出现在SpringMVC中,利用ajax和json获取集合类型参数时产生的。
代码
由jsp页面产生数据,并传递给Controller层。
<head>
<title>Title</title>
<script src="${pageContext.request.contextPath}/js/jquery-3.3.1.js"></script>
<script>
var userList = new Array();
userList.push({username:"zhangsan",age:18});
userList.push({username:"lisi",age:28});
$.ajax({
dataType:'json',
type:"POST",
url:"${pageContext.request.contextPath}/user/quick14",
data:JSON.stringify(userList),
contentType:"application/json;charset=UTF-8"
});
</script>
</head>
接收:
@Controller
public class UserController {
@RequestMapping("/quick2")
@ResponseBody
public void save2(@RequestBody List<User> userList){
System.out.println(userList);
}
}
spring-mvc.xml中:
<context:component-scan base-package="nuc.ss.Controller"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- /jsp/success.jsp -->
<property name="prefix" value="/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:resources mapping="/js/**" location="/js/"/>
注意点
①如果在Controller层的对应方法上,没有写 @ResponseBody ,那么就会直接导致该错误。
②注意扫描注解时,对应的包一定要正确。
③一定要加载静态资源 <mvc:resources mapping="/js/**" location="/js/"/>
后来又出现了该问题,我把加载静态资源的配置语句 <mvc:resources mapping="/js/**" location="/js/"/>
去掉之后,竟然可以了,不知道什么情况。
推荐阅读
-
No mapping found for HTTP request with URI [/springmvc-1/springmvc/testParamsAndHeaders] in Dispatch
-
vue+No mapping found for HTTP request with URI [*//**] in DispatcherServlet with name ‘springMvc‘
-
异常记录二:寻求解决异常 !No mapping found for HTTP request with URI
-
如何解决“ No mapping found for HTTP request with URI [XXX] in DispatcherServlet with name 'XXX' ”
-
警告: No mapping found for HTTP request with URI [/springmvc-01/helloworld] in DispatcherServlet with
-
No mapping found for HTTP request with URI [/xxx/xxx] in DispatcherServlet with name 'xxx'
-
No mapping found for HTTP request with URI [...] in DispatcherServlet with name ‘DispatcherServlet‘
-
No mapping found for HTTP request with URI [***.html] in DispatcherServlet with name "***"
-
No mapping found for HTTP request with URI [/HelloWeb/] in DispatcherServlet with name 'HelloWeb...
-
No mapping found for HTTP request with URI [/app17a/] in DispatcherServlet with name 'springmvc'解决方法