直接原因是:我的(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. postman测试带有json数据格式的字段

    测试六个字段 普通字段: ModelCode 普通字段: MmodelCode 普通字段: ModelTagKey 普通字段: ModelTagValue 普通字段: ModelTagType jso ...

  2. Web基础之Redis

    Redis 什么是Redis?Redis是一个基于内存的非关系型数据库,简单来说就是一个可持久化的高速缓存. 常用场景: 缓存(数据查询,端链接,新闻内容,商品内容等等)--使用最多 聊天室的在线好友 ...

  3. POJ 2251 Dungeon Master(三维空间bfs)

    题意:三维空间求最短路,可前后左右上下移动. 分析:开三维数组即可. #include<cstdio> #include<cstring> #include<queue& ...

  4. POJ 1045:Bode Plot

    Bode Plot Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13392   Accepted: 8462 Descri ...

  5. C++编程学习(四)声明/枚举

    一.typedef 声明 typedef 为一个已有的类型取一个新的名字 typedef int num;//feet是int的另一个名字num a;//a是int类型 二.枚举类型 enum col ...

  6. InstrumentationTextCase 测试

    <instrumentation        android:name="android.test.InstrumentationTestRunner"        an ...

  7. 春节宅家火了短视频,手游 APP 成最大赢家!

    春节历来是APP运营者翘首以盼的火热期,但2020年的春节有些特殊, 新型冠状病毒的爆发,牵动着全国亿万人民的心.响应号召不出门,宅在家里玩手机,于是打游戏.看新闻.追剧等成为大家打发时间.疏解内心压 ...

  8. No enclosing instance of type test is accessible. Must qualify the allocation with an enclosing inst

    今日遇到一个报错如下: No enclosing instance of type test is accessible. Must qualify the allocation with an en ...

  9. dwz框架

    官网:http://jui.org/index_menu.html PDF教程:http://jui.org/doc/dwz-user-guide.pdf DWZ最大的特点是使用html扩展的方式来代 ...

  10. POJ 2006:Litmus Test 化学公式

    Litmus Test Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1709   Accepted: 897 Descri ...