zoukankan      html  css  js  c++  java
  • SpringMVC异常报406 (Not Acceptable)的解决办法

    使用SpsringMVC,使用restEasy调试,controller请求设置如下: 

    Java代码  收藏代码
    1. @RequestMapping(value="/list",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)  
    2. @ResponseBody  
    3. public List<EditTimeout> list(){  
    4.      List<EditTimeout> list = editImpl.selectAll();  
    5.     return list;  
    6. }  



    请求,debug跟踪list是返回值没有问题,但是前台页面报如下错误: 

    Java代码  收藏代码
    1. Response Status: 406 (Not Acceptable)  



    Response RAW返回值如下,(前半部分) 

    Xml代码  收藏代码
    1. HTTP GET http://127.0.0.1:8080/onlineLibrary/rest/system/editTimeout/list  
    2. Host: 127.0.0.1:8080  
    3.   
    4.   
    5. 406 Not Acceptable  
    6. Date: Sat, 17 Aug 2013 11:01:07 GMT  
    7. Server: Apache-Coyote/1.1  
    8. Content-Length: 1067  
    9. Content-Type: text/html;charset=utf-8  
    10. <html><head><title>Apache Tomcat/7.0.34 - Error report</title><style>  



    后台提示错误: 

    Java代码  收藏代码
    1. 2013-08-17 19:01:03,116 DEBUG org.springframework.web.servlet.DispatcherServlet -Last-Modified value for [/onlineLibrary/rest/system/editTimeout/list] is: -1  
    2. 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  
    3. 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  
    4. 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问题解决。

  • 相关阅读:
    hdu 1588 求f(b) +f(k+b) +f(2k+b) +f((n-1)k +b) 之和 (矩阵快速幂)
    poj 3233 S = A + A^2 + A^3 + … + A^k A是一个n X n矩阵 (矩阵快速幂)
    hdu 1757 和1005差不多 (矩阵快速幂)
    D 矩阵快速幂
    poj 3734 方块涂色 求红色 绿色方块都为偶数的方案数 (矩阵快速幂)
    hdu 1005 根据递推公式构造矩阵 ( 矩阵快速幂)
    hdu 4549 M斐波拉契 (矩阵快速幂 + 费马小定理)
    UVa 1643 Angle and Squares (计算几何)
    UVa 11040 Add bricks in the wall (水题递推)
    UVa 1336 Fixing the Great Wall (区间DP)
  • 原文地址:https://www.cnblogs.com/dauber/p/9265961.html
Copyright © 2011-2022 走看看