直接原因是:我的(maven)项目parent父工程pom.xml缺少必要的三个jar包依赖坐标。

解决方法是:在web子模块的pom.xml里面添加springMVC使用JSON实现AJAX请求。

<!--spring mvc-json依赖-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.9</version>
</dependency>
<spring.version>5.0.15.RELEASE</spring.version>

jsp页面的<script>标签

            //用jQuery实现AJAX请求提交数据到服务器端
//保存数据到服务器,成功时控制台打印显示信息
var selectListTest = new Array();
selectListTest[0] = "param1";
selectListTest[1] = "param2";
selectListTest[2] = "param3";
$.ajax({
type:"POST",
url:"${pageContext.request.contextPath}/product/delete.do",
contentType:"application/json",//jQuery的ajax提交数组使得springMVC使用必填参数
//接收用@requestBody
data:JSON.stringify(selectListTest), //数组通过JSON.stringify格式化
success:function (data) {
alert(data);
} });

视图层Controller类的Method

    //删除产品的某个分类通过产品编号
@RequestMapping("/delete.do")
@ResponseBody
public String deleteByNum(@RequestBody List<String> selectListTest)throws Exception{
System.out.println( "JSP页面通过AJAX技术提交POST请求的路径找到。" );
// productService.deleteByNum(product); System.out.println( selectListTest );
System.out.println( "JSP页面通过AJAX技术提交字符串数组成功实现。" ); return"redirect:findAll.do";
}

总结一下,解决该问题需注意一下三点:

1.  使用jackson依赖jar包。

2.  jQuery的 $.ajax() 里面需要对JSP页面里的字符串数组提交之前格式化。

var testList=['1','2','3'];
$.ajax({
type: "post",
url: "${pageContext.request.contextPath}/product/delete.do",
contentType:"application/json",
data:JSON.stringify(testList),
success: function(obj){
alert(obj.description);
},
error: function(obj){
alert("操作出错");
return false;
}
});

3. Controller控制层AJAX请求的调用的方法需在参数前加 @RequestBody注解。

  

public void method(@RequestBody List<String> testList) {

  return;
}

==================
end

参考资料:

关于Ajax请求传递数组参数的解决办法

												

SpringMVC在使用JSON时报错信息为:Content type 'application/json;charset=UTF-8' not supported的更多相关文章

  1. Jmeter发送post请求报错Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    常识普及: Content-type,在Request Headers里面,告诉服务器,我们发送的请求信息格式,在JMeter中,信息头存储在信息头管理器中,所以在做接口测试的时候,我们维护Conte ...

  2. org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported

    最后找到我的问题,springmvc配置文件中没加 <mvc:annotation-driven/> java代码: @RequestMapping(value="/reques ...

  3. Content type 'application/json;charset=UTF-8' not supported异常的解决过程

    首先说一下当时的场景,其实就是一个很简单的添加操作,后台传递的值是json格式的,如下图 ,后台对应的实体类, @Data @EqualsAndHashCode(callSuper = false) ...

  4. ajax使用向Spring MVC发送JSON数据出现 org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported错误

    ajax使用向Spring MVC发送JSON数据时,后端Controller在接受JSON数据时报org.springframework.web.HttpMediaTypeNotSupportedE ...

  5. springboot 报错 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    开始 controller 方法写的是 @RequestMapping( value = "/add", method = RequestMethod.POST ) public ...

  6. org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported或其他Content type不支持处理

    很久没从头到尾搭框架,今天搭的过程中,springmvc controller方法入参用@RequestBody自动绑定参数时一直提示各种 not supported 排查问题有两个解决路径: 1)使 ...

  7. Resource interpreted as Document but transferred with MIME type application/json laravel异常请求返回警告

    一般情况下,laravel在方法里可以向前端返回数组格式 return [], 框架可以自动将数组转成JSON字符串返回,但浏览器会报MIME类型警告, 如是做APP接口可以忽视该警告: 但在前端aj ...

  8. 解决IE浏览器中出现“Resource interpreted as Document but transferred with MIME type application/json”问题

    在上传图片时,使用ajax提交,返回的数据格式为json.在测试时发现IE浏览器中,上传图片后,没有显示图片,而是弹出一个提示:是否保存UploadImg.json文件:而在其他浏览器中正常. 在Ch ...

  9. ajax 发送json数据时为什么需要设置contentType: "application/json”

    1. ajax发送json数据时设置contentType: "application/json”和不设置时到底有什么区别? contentType: "application/j ...

随机推荐

  1. python之os.exec*族用法简结

    os.exec*族主要用来代替当前进程,执行新的程序,不返回值.在UNIX上,新的执行程序加载到当前进程,与调用它的进程有相同的id. os.execl(path, arg0, arg1, ...) ...

  2. 执行 composer update 命令的时候报 Your requirements could not be resolved to an installable set of packages. 错误

    Your requirements could not be resolved to an installable set of packages. 以上原因:不匹配composer.json要求的版 ...

  3. 每天一点点之vue框架开发 - vue中使用vue-router切换页面时自动滚动到顶部的方法

    1. 在main.js入口文件中写入 //路由跳转后,页面回到顶部 router.afterEach(() => { document.body.scrollTop = 0; document. ...

  4. 通过Request获取客户端的真实IP

    我们在做项目的时候经常需要获取客户端的真实ip去进行判断,为此搜索了相关文章,以下这个讲解的比较明白,直接拿来 https://blog.csdn.net/yin_jw/article/details ...

  5. 【pwnable.kr】 flag

    pwnable从入门到放弃 第四题 Download : http://pwnable.kr/bin/flag 下载下来的二进制文件,对着它一脸懵逼,题目中说是逆向题,这我哪会啊... 用ida打开看 ...

  6. CSS - input 美化

    input{ padding: 20px; width: 100%; height: 5vh; margin-bottom: 2vh; border-radius: 10vw; border: 0; ...

  7. H5 - 本地数据存储 - localStorage.setItem

  8. 实验吧Web-易-天网管理系统(php弱类型,==号)

    打开网页,查看源码,看到 <!-- $test=$_GET['username']; $test=md5($test); if($test=='0') --> 说明用户名需要加密之后为0. ...

  9. SASS - 简介

    SASS – 简介 SASS – 环境搭建 SASS – 使用Sass程序 SASS – 语法 SASS – 变量 SASS- 局部文件(Partial) SASS – 混合(Mixin) SASS ...

  10. scanf与gets

    gets函数为什么不能读取字符就往下运行了 这里有一个共性的问题,就是 scanf 输入后,会遗留一个回车符,传递到下面的输入语句: 回车符就会被下面的输入语句接收,而结束了输入,这里就是一个错误的值 ...