数据传递-------ajaxJson------spring3mvc中使用ajax传json中文乱码解决
参考来源:http://blog.csdn.net/dangerous_fire/article/details/25904225
第一种解决方法,适用所有情况
因为在controller中返回json用了@ResponseBody,而spring源码中@ResponseBody 的实现类发现其默认的编码是 iso-8859-1,而项目用的编码为utf-8,所以传中文会出现乱码,解决办法是不用注解,直接用response,转换编码。
- @RequestMapping("/modifyconfiginput")
 - @ResponseBody
 - public String modifyinput( @RequestParam(value="id") String id,
 - @RequestParam(value="timestamp") String timestamp,
 - HttpServletResponse response ) throws Exception {
 - ImmediateConfig ic = this.immediatePictureService.findImmediateConfig(id);
 - String json = "["+"{name:'"+ic.getName()+"',classId:'"+ic.getProductClass().getClassId()+"',pyFile:'"+ic.getPyFile()+"'}]";
 - System.out.println("json:"+json);
 - //return json;
 - // 设置response的ContentType解决中文乱码
 - response.setContentType("text/html;charset=UTF-8");
 - response.getWriter().print(json);
 - return null;
 - }
 
第二种解决方法,可用于新版本的spring
- @RequestMapping(value="/ajaxCounterList", produces = "application/json; charset=utf-8")
 
注意:在IE浏览器中必须声明返回的类型,如下
@RequestMapping(value="/upload/upload",produces="text/html;charset=UTF-8")
或者用第一种方法,但也要声明为 text/html 类型,否则IE无法识别,会报错误
- Servlet.service() for servlet springMVC threw exception
 - 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中文乱码解决的更多相关文章
- jquery的ajax()函数传值中文乱码解决方法介绍
		
jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 代码如下: $.ajax({ dataType : ‘json', type : ‘POST', url : ‘http: ...
 - ajax()函数传值中文乱码解决方法介绍
		
jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 复制代码 代码如下: $.ajax({ dataType : ‘json',type : ‘POST',url : ‘ht ...
 - JSP中Get提交方式的中文乱码解决
		
最近对JSP&Servlert的原理很感兴趣,所以今天花时间看了一下:无奈在一个编码问题上困扰很久 这是我的解决思路: (1)检查网页(html/jsp)页面的编码: (2)检查服务器端的处理 ...
 - springmvc框架下ajax请求传参数中文乱码解决
		
springmvc框架下jsp界面通过ajax请求后台数据,传递中文参数到后台显示乱码 解决方法:js代码 运用encodeURI处理两次 /* *掩码处理 */ function maskWord( ...
 - [转]IE、FireFox、Chrome浏览器中关于URL传参中文乱码,解决兼容性问题!
		
原文地址:https://cloud.tencent.com/developer/article/1334736 前台用url传值中文,后台用request.getParameter接收参数.在Fir ...
 - url传参中文乱码解决
		
url传参request.setCharacterEncoding("utf-8");无法解决中文乱码问题 解决方法: 修改tomcat---conf----server.xml文 ...
 - springMVC中前台ajax传json数据后台controller接受对象为null
		
在jquery的ajax中,如果没加contentType:"application/json",那么data就应该对应的是json对象,反之,如果加了contentType:&q ...
 - ajax url参数中文乱码解决
		
1.较好的处理办法,对js的url中的中文参数值使用两次encodeURI(),即 encodeURI(encodeURI("url的中文参数值")), java代码中使用URLD ...
 - ajax url参数中文乱码解决方法
		
较好的处理办法,对js的url中的中文参数值使用两次encodeURI(),即encodeURI(encodeURI("url的中文参数值")) JS代码: var name=&q ...
 
随机推荐
- codevs1792 分解质因数
			
题目描述 Description 编写一个把整数N分解为质因数乘积的程序. 输入描述 Input Description 输入一个整数 N 输出描述 Output Description 输出 分解质 ...
 - Surprising Strings
			
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description ...
 - [bzoj1934/2768][Shoi2007]Vote 善意的投票_最小割
			
Vote 善意的投票 bzoj-1934 Shoi-2007 题目大意:题目链接. 注释:略. 想法: 这是最小割的一个比较基本的模型. 我们将所有当前同意的小朋友连向源点,边权为1.不容易的连向汇点 ...
 - java压缩与解压文件
			
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import ...
 - symfony could not load type 'datetime'
			
当用curd生成控制器后,当修改的时候,会有这个提示,解决方法 在orm中通过事务的方式填充时间,然后把生成的form中的文件的时间段去掉 $builder ->add('title') -&g ...
 - 8VC Venture Cup 2016 - Final Round (Div2) E
			
贪心.当前位置满油可达的gas station中,如果有比它小的,则加油至第一个比他小的.没有,则加满油,先到达这些station中最小的.注意数的范围即可. #include <iostrea ...
 - SQLite数据库基本操作
			
SQLite 是一个开源的嵌入式关系数据库,实现自包容.零配置.支持事务的SQL数据库引擎. 其特点是高度便携.使用方便.结构紧凑.高效.可靠. 与其他数据库管理系统不同,SQLite 的安装和运行非 ...
 - 改动ScrollView的滑动速度和解决ScrollView与ViewPager的冲突
			
话不多说,非常easy,能够从凝视中知道做法,直接上代码: 1.改动ScrollView的滑动速度: public class MyHorizontalScrollView extends Horiz ...
 - Android API Guides –System Permissions
			
系统权限 声明: 本文由Gordon翻译 公布于www.dlvoice.com 欢迎转载,但请保留此声明 原文地址:http://developer.android.com/guide/topics/ ...
 - Python正則表達式小结(1)
			
学习一段python正則表達式了, 对match.search.findall.finditer等函数作一小结 以下以一段网页为例,用python正則表達式作一个范例: strHtml = '''& ...