`

Spring MVC遇到HttpStatus 406 not acceptable 异常

 
阅读更多

   今天项目突然遇到HTTPstatus406 异常,总所周知,406状态码表示的是,资源已经找到,只是该资源的MIME类型跟请求头的accept不一致。追根朔源,发现原来是请求json数据,返回的却是字符串。尴尬

 以为之前未了修改StringHttpMessageConverter的默认字符集ISO-8859-1为UTF-8所以添加一下内容。

  <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
        <property name="messageConverters">  
             <list>  
                 <bean class = "org.springframework.http.converter.StringHttpMessageConverter">  
                    <property name = "supportedMediaTypes">  
                          <list>  
                              <value>text/html;charset=UTF-8</value>  
                         </list>  
                    </property>  
                 </bean>  
            </list>  
        </property>  
</bean> 

 结果忘记添加其他转换器,导致后台无法转换json数据。

解决办法:

添加MappingJacksonHttpMessageConverter转换器

  <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
        <property name="messageConverters">  
             <list>  
                 <bean class = "org.springframework.http.converter.StringHttpMessageConverter">  
                    <property name = "supportedMediaTypes">  
                          <list>  
                              <value>text/html;charset=UTF-8</value>  
                         </list>  
                    </property>  
                 </bean>  
               <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
            </list>  
        </property>  
</bean> 

    

分享到:
评论

相关推荐

    Whether mandatory donation is acceptable or not?

    Whether mandatory donation is acceptable or not?

    jackson-core-asl-1.9.13及jackson-mapper-asl-1.9.13架包.rar

    可用于Spring MVC框架,spring MVC中返回使用@ResponseBody注解返回时,后台没报错,就控制台显示406 Not Acceptable 原因是缺少jackson的包:jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar

    elasticsearch-head

    ## Synopsis ... ## Motivation This was created because ElasticSearch 5 removed the ability to run ElasticSearch Head as an Elastic Plugin. This offers an alternative to self-hosting in your own web ...

    jackson的包:jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar

    spring MVC中返回使用@ResponseBody注解返回时,后台没报错,就控制台显示406 Not Acceptable 原因是缺少jackson的包:jackson-core-asl-1.9.2.jar和jackson-mapper-asl-1.9.2.jar

    JSP页面报错列表查询

    406 Not Acceptable 指定的资源已经找到,但它的MIME类型和客户在Accpet头中所指定的不兼容(HTTP 1.1新)。 407 Proxy Authentication Required 类似于401,表示客户必须先经过代理服务器的授权。(HTTP 1.1新) ...

    Resizes Images to sizes acceptable by half life for transiti

    Resizes Images to sizes acceptable by half life for transitioning into pldecal.wad files This code is incomplete... A Majority of the programming has been accomplished.

    ANSI-ASHRAE Standard 62.1-2019 Ventilation for Acceptable Indoor

    ANSI-ASHRAE Standard 62.1-2019 Ventilation for Acceptable Indoor

    Crawler.zip

    一个简单的网络爬虫资源包,是之前在发现的,文件包好像还挺完整,本来应该免积分的,但是因为急需积分,所以设置为两积分,有兴趣的可以下载试试

    play-content-negotiation:Play框架的声明式内容协商

    不幸的是,这种方法存在问题:如果服务器需要返回406 Not Acceptable HTTP响应,则Play框架无法在响应中提供受支持的内容类型的列表,这对于开发人员编程客户端非常有帮助。用于您的Web应用程序。 play-content-...

    servlet2.4doc

    Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. encodeUrl(String) - Method in class javax.servlet....

    rack-accepts:[UNMAINTAINED] 机架中间件拒绝蹩脚的 http 接受标头

    机架中间件拒绝蹩脚的 http 接受标头当请求不支持的类型时返回“406 Not Acceptable”状态。导轨用法 config.middleware.use Rack::Accepts执照版权所有 (c) 2010 Andrew Nesbitt 特此授予任何人免费获得本软件副本...

    SIP - Understanding the Session Initiation Protocol, 2nd Ed - 1459

    5.4.7 406 Not Acceptable 115 5.4.8 407 Proxy Authentication Required 115 5.4.9 408 Request Timeout 116 5.4.10 409 Conflict 116 5.4.11 410 Gone 116 5.4.12 411 Length Required 116 5.4.13 413 Request ...

    HTTP协议详解

    10.4.7 406 不接受的 (Not Acceptable) 10.4.8 407 代理服务器授权所需(Proxy Authentication Required) 10.4.9 408 请求超时(Request Timeout) 10.4.10 409 冲突 (Confilict) 10.4.11 410 不存在(gone) ...

    sip RFC3261 中文版

    21.4.7 406 Not Acceptable 209 21.4.8 407 Proxy Authentication Required 209 21.4.9 408 Request Timeout 210 21.4.10 410 Gone 210 21.4.11 413请求实体过大。 210 21.4.12 414 Request-URI Too Long 210 21.4....

    Http1.1超文本传输协议中文版

    10.4.7 406 不接受的 (Not Acceptable) 65 10.4.8 407 代理服务器授权所需(Proxy Authentication Required) 65 10.4.9 408 请求超时(Request Timeout) 65 10.4.10 409 冲突 (Confilict) 65 10.4.11 410 不...

    How to implement SCP-ECG, Part II

    It is not anymore acceptable that, in the age of information technology, millions of Euros are wasted for unnecessarily repeated tests or that patients do not obtain appropriate care because relevant ...

    node-contrib-mvcgenerator:一种基于简单的JSON配置来搭建MVC项目的工具

    node-contrib-mvcgenerator一种基于简单的JSON配置来搭建MVC项目的工具。 注意:此项目无需维护-此处存在更好的替代方法: : 配置文件示例: exports . config = { // filename extensions - acceptable formats: js...

    HowToImplement SCP-ECG_Part I

    It is not anymore acceptable that, in the age of information technology, millions of Euros are wasted for unnecessarily repeated tests or that patients do not obtain appropriate care because relevant ...

    LaTeX模板llncs

    部分国内外会议的LaTeX模板Lecture Notes in Computer Science (LNCS) ...Each contribution must be accompanied by a Springer copyright form, a so-called 'Consent to ... Modified forms are not acceptable.

    svm数据挖掘挖掘挖掘挖掘挖掘挖掘挖掘

    acceptable results. Although users do not need to understand the underlying theory behind SVM, we brie y introduce the basics necessary for explaining our procedure. A classi cation task usually ...

Global site tag (gtag.js) - Google Analytics