jsonp+springmvc解决跨域问题请求参数乱码问题

**使用jsonp,即使设置ajax请求为POST,TM会将其转为GET请求. 这样web.xml设置的springmvc的CharacterEncodingFilter不起作用.
执行request.setCharacterEncoding("utf-8")对GET请求是无效的!**>(!错误!)
[更正]之所以会变成GET请求不是jsonp的过错,而是idea里面用浏览器打开html后,可以用http协议. 但是会将post换成get.

请看下面的请求头:

Request URL: http://localhost:8089/search.do?callback=jQuery11210772629357678043_1528177787309&searchType=%E5%A7%93%E5%90%8D&searchContent=%E6%9D%8E%E5%9B%9B&_=1528177787310
Request Method: GET

js

$.ajax({
    type: 'POST',url: requestArguments.url,data: requestArguments.data,success: function (responseResult) {
}.bind(this),dataType: 'jsonp'</code></pre>

后台controller部分代码

头部:

@RequestMapping(value = {"/search"})  //http://localhost:8080/certno/110101195607302022.do
    @ResponseBody
    public MappingJacksonValue searchGraph(String searchType,String searchContent,@RequestParam(value = "callback",required = false) String callback,HttpServletResponse response) throws CustomException {
   ....

    //构造MappingJacksonValue,SpringMVC配合jsonp<a href="https://www.jb51.cc/tag/jiejue/" target="_blank" class="keywords">解决</a>浏览器跨域访问问题
    MappingJacksonValue mjv = new MappingJacksonValue(responseResult);
    mjv.setJsonpFunction(callback);

    return mjv;

**使用jsonp,TM会将其转为GET请求. 这样web.xml设置的springmvc的CharacterEncodingFilter不起作用.
执行request.setCharacterEncoding("utf-8")对get请求是无效的!**

所以,还是乖乖的将Tomcat的server.xml的配置改下吧.

相关文章

SpringMVC1.MVC架构MVC是模型(Model)、视图(View)、控制...
SpringMVC学习笔记1.SpringMVC应用1.1SpringMVC简介​Spring...
11.1数据回显基本用法数据回显就是当用户数据提交失败时,自...
一、SpringMVC简介1、SpringMVC中重要组件DispatcherServlet...
1.它们主要负责的模块Spring主要应用于业务逻辑层。SpringMV...
3.注解开发Springmvc1.使用注解开发要注意开启注解支持,2.注...