参考来源:http://blog.csdn.net/dangerous_fire/article/details/25904225

第一种解决方法,适用所有情况

因为在controller中返回json用了@ResponseBody,而spring源码中@ResponseBody 的实现类发现其默认的编码是 iso-8859-1,而项目用的编码为utf-8,所以传中文会出现乱码,解决办法是不用注解,直接用response,转换编码。

  1. @RequestMapping("/modifyconfiginput")
  2. @ResponseBody
  3. public String modifyinput( @RequestParam(value="id") String id,
  4. @RequestParam(value="timestamp") String timestamp,
  5. HttpServletResponse response ) throws Exception {
  6. ImmediateConfig ic = this.immediatePictureService.findImmediateConfig(id);
  7. String json = "["+"{name:'"+ic.getName()+"',classId:'"+ic.getProductClass().getClassId()+"',pyFile:'"+ic.getPyFile()+"'}]";
  8. System.out.println("json:"+json);
  9. //return json;
  10. // 设置response的ContentType解决中文乱码
  11. response.setContentType("text/html;charset=UTF-8");
  12. response.getWriter().print(json);
  13. return null;
  14. }

第二种解决方法,可用于新版本的spring

  1. @RequestMapping(value="/ajaxCounterList", produces = "application/json; charset=utf-8")

注意:在IE浏览器中必须声明返回的类型,如下

@RequestMapping(value="/upload/upload",produces="text/html;charset=UTF-8")

或者用第一种方法,但也要声明为 text/html 类型,否则IE无法识别,会报错误

    1. Servlet.service() for servlet springMVC threw exception
    2. java.lang.IllegalStateException: <span style="color:#FF0000;">Current request is not of type</span> [org.springframework.web.multipart.MultipartHttpServletRequest]: org.apache.catalina.connector.RequestFacade@58fbd53e

数据传递-------ajaxJson------spring3mvc中使用ajax传json中文乱码解决的更多相关文章

  1. jquery的ajax()函数传值中文乱码解决方法介绍

    jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 代码如下: $.ajax({ dataType : ‘json', type : ‘POST', url : ‘http: ...

  2. ajax()函数传值中文乱码解决方法介绍

    jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 复制代码 代码如下: $.ajax({ dataType : ‘json',type : ‘POST',url : ‘ht ...

  3. JSP中Get提交方式的中文乱码解决

    最近对JSP&Servlert的原理很感兴趣,所以今天花时间看了一下:无奈在一个编码问题上困扰很久 这是我的解决思路: (1)检查网页(html/jsp)页面的编码: (2)检查服务器端的处理 ...

  4. springmvc框架下ajax请求传参数中文乱码解决

    springmvc框架下jsp界面通过ajax请求后台数据,传递中文参数到后台显示乱码 解决方法:js代码 运用encodeURI处理两次 /* *掩码处理 */ function maskWord( ...

  5. [转]IE、FireFox、Chrome浏览器中关于URL传参中文乱码,解决兼容性问题!

    原文地址:https://cloud.tencent.com/developer/article/1334736 前台用url传值中文,后台用request.getParameter接收参数.在Fir ...

  6. url传参中文乱码解决

    url传参request.setCharacterEncoding("utf-8");无法解决中文乱码问题 解决方法: 修改tomcat---conf----server.xml文 ...

  7. springMVC中前台ajax传json数据后台controller接受对象为null

    在jquery的ajax中,如果没加contentType:"application/json",那么data就应该对应的是json对象,反之,如果加了contentType:&q ...

  8. ajax url参数中文乱码解决

    1.较好的处理办法,对js的url中的中文参数值使用两次encodeURI(),即 encodeURI(encodeURI("url的中文参数值")), java代码中使用URLD ...

  9. ajax url参数中文乱码解决方法

    较好的处理办法,对js的url中的中文参数值使用两次encodeURI(),即encodeURI(encodeURI("url的中文参数值")) JS代码: var name=&q ...

随机推荐

  1. 【ZJOI2017 Round1练习】D8T3 stone(Nim游戏)

    题意: 思路:与其类似的题是HDU5996 HDU5996为判定性问题,稍加改动就可以用来统计方案数 ..]of longint; v,cas,i,j,ans,tmp,n,s,k:longint; b ...

  2. POJ 2828 Buy Tickets (线段树 || 树状数组)

    题目大意 一些小朋友在排队,每次来一个人,第i个人会插到第x个人的后面.权值为y.保证x∈[0,i-1]. 按照最后的队伍顺序,依次输出每个人的权值. 解题分析 好气吖.本来是在做splay练习,然后 ...

  3. jquery控制Request Payload和Form Data

    Request Payload方式,会发起两次请求 Form Data只发起一次请求 若要把一个ajax请求改为Payload方式,设置contentType即可,发现请求参数不是对象,再把参数转换为 ...

  4. POJ3728 The merchant解题报告

    Description There are N cities in a country, and there is one and only one simple path between each ...

  5. systemtap 作用-- SystemTap使用技巧

    http://blog.csdn.net/wangzuxi/article/details/42849053

  6. 【Nginx】epoll及内核源码详解

    内核源码: https://www.nowcoder.com/discuss/26226?type=0&order=0&pos=21&page=1 epoll流程: 首先调用e ...

  7. Linux system log avahi-daemon[3640]: Invalid query packet.

    2014-06-11 Check the Linux system log find the errorr: Jun  9 11:18:49 hostname avahi-daemon[3640]: ...

  8. GETTING STARTED WITH THE OTTO JAVASCRIPT INTERPRETER

    原文: https://www.fknsrs.biz/blog/otto-getting-started.html.html GETTING STARTED WITH THE OTTO JAVASCR ...

  9. 一个Navi过程下多个DocumentCompleted事件问题的解决的方法

    7.16 Marked to Write.... 七月份马克的一篇文章了,今天才想起来把他写完,呵呵. 原本是七月份用来做微博爬虫的,后来发现新浪对机器人的检測不好绕过,连简单地訪问都会被检測出来,后 ...

  10. form 表单序列化 serialize

    在开发中有时需要在js中提交form表单数据,就需要将form表单进行序列化. jquery提供的serialize方法能够实现. $("#searchForm").seriali ...