使用SpsringMVC,使用restEasy调试,controller请求设置如下:
@RequestMapping(value="/list",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<EditTimeout> list(){
List<EditTimeout> list = editImpl.selectAll();
return list;
}
请求,debug跟踪list是返回值没有问题,但是前台页面报如下错误:
Response Status: 406 (Not Acceptable)
Response RAW返回值如下,(前半部分)
HTTP GET http://127.0.0.1:8080/onlineLibrary/rest/system/editTimeout/list
Host: 127.0.0.1:8080
406 Not Acceptable
Date: Sat, 17 Aug 2013 11:01:07 GMT
Server: Apache-Coyote/1.1
Content-Length: 1067
Content-Type: text/html;charset=utf-8
<html><head><title>Apache Tomcat/7.0.34 - Error report</title><style>
后台提示错误:
2013-08-17 19:01:03,116 DEBUG org.springframework.web.servlet.DispatcherServlet -Last-Modified value for [/onlineLibrary/rest/system/editTimeout/list] is: -1
2013-08-17 19:01:07,606 DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2013-08-17 19:01:07,680 DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
2013-08-17 19:01:07,681 DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver -Resolving exception from handler [public java.util.List<com.online.ol.filter.EditTimeout> com.online.ol.filter.EditTimeoutContoller.list()]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
引起的原因:
由于设置了@ResponseBody,要把对象转换成json格式,缺少转换依赖的jar包,故此错。
解决办法:
加入依赖的jar,jackson-core-asl-1.9.12.jar,jackson-mapper-asl-1.9.12.jar问题解决。
分享到:
相关推荐
springmvc异常处理的博文如下: http://blog.csdn.net/dlf123321/article/details/50756003
异常一层一层的向上抛出,但是开发人员肯定不想要用户看到代码出错,因此需要将异常屏蔽了,SpringMVC提供了异常处理的手段。
NULL 博文链接:https://mryangjw.iteye.com/blog/1772422
主要介绍了SPRINGMVC 406问题解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
12SpringMVC异常处理.md
SpringMVC中异常处理机制,简单案例,里面有详细说明以及博客说明。
springmvc返回json的全局异常统一处理demo,有问题可以留言。
springMVC框架遇到中文乱码的解决思路汇总,包括从配置到注解的详细描述,帮助开发人员解决spirngMVC中文乱码问题
SpringMVC简介与多线程解决方案SpringMVC简介与多线程解决方案SpringMVC简介与多线程解决方案
主要介绍了SpringMVC异常处理器编写及配置,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
SpringMVC + spring3.1.1 + hibernate4.1.0 集成及常见问题总结 SpringMVC spring hibernate 集成 常见问题
springMVC3学习(八)--全局的异常处理(源码) 文章地址:http://blog.csdn.net/itmyhome1990/article/details/26286435
SpringMVC笔记内容:第一天(SpringMVC的概述、SpringMVC与Struts2优势分析、重要组件、运行原理、SpringMVC环境搭建、@RequestMapping注解详解、...第三天(SpringMVC异常处理、自定义拦截器、拦截器栈) --author:
ssm-springMVC-整合Quartz(解决了无法注入service问题).doc
springmvc提供视频播放功能时,手机端无法正常播放的解决办法
本文档主要介绍了SpringMVC的ModelAndView机制,使用SpringMVC实现文件上传,下载以及全局异常处理机制
SSM笔记-SpringMVC的异常处理,包含了ExceptionHandler注解、ResponseStatusExceptionResolver、DefaultHandlerExceptionResolver、SimpleMappingExceptionResolver的使用和试验
SpringMVC注解return参数出现乱码解决方案。
springmvc是常用的一种框架,学习springmvc非常重要,故需要良好教程资料
用来解决SpringMVC+Ajax技术中前台报406的错误信息,实现后台json格式与前台一致