springMVC @response 中文乱码解决
以下任选一种
在web.xml中:
添加一个过滤器(filter),注册 org.springframework.web.filter.CharacterEncodingFilter
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
全局修改输出为UTF-8编码:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!-- utf-8编码 -->
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
</beans>
编码问题
如何设置,才能避免乱码?
Producer/Consumer (生产/消费模式)。
// 请求内容类型必须为 text/html
@RequestMapping(value="/aaa", consumes="text/html"); // 客户端接收 json 且编码为 utf-8
@RequestMapping(value="/bbb", produces="application/json; charset=UTF-8");
springMVC @response 中文乱码解决的更多相关文章
- jmeter解决request response中文乱码问题
一:主要内容 解决request请求入参中文乱码问题 解决response响应数据中文乱码问题 二:解决request和response中文乱码问题 request结果:-中文已经不乱码了 respo ...
- 解决Charles Response 中文乱码
Response中文乱码:在Info.plist 中 的vmoption 添加-Dfile.encoding=UTF-8 info.plist路径 应用程序->Charles.app->显 ...
- springmvc字符 中文乱码问题
springmvc字符 中文乱码问题 1.字符过滤器 输入中文测试,发现乱码 以前乱码问题通过过滤器解决 , 而SpringMVC给我们提供了一个过滤器 , 可以在web.xml中配置,修改了xml文 ...
- Javaee中文乱码解决方法
分类: javaee2015-07-09 16:35 29人阅读 评论(0) 收藏 编辑 删除 post 中文乱码解决方式 接受数据的时候设置 request.setCharacterEncoding ...
- Django 分页查询并返回jsons数据,中文乱码解决方法
Django 分页查询并返回jsons数据,中文乱码解决方法 一.引子 Django 分页查询并返回 json ,需要将返回的 queryset 序列化, demo 如下: # coding=UTF- ...
- Java 前台后台数据传递、中文乱码解决方法
1.向前台传递数据;2.向后台传递数据;3.ajax post 提交数据到服务端时中文乱码解决方法;4.数组类型参数传递; 1.向前台传递数据:1.1 字符串数据传递: 这种方式只是单一的向前台传递 ...
- ajax()函数传值中文乱码解决方法介绍
jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 复制代码 代码如下: $.ajax({ dataType : ‘json',type : ‘POST',url : ‘ht ...
- JSP中Get提交方式的中文乱码解决
最近对JSP&Servlert的原理很感兴趣,所以今天花时间看了一下:无奈在一个编码问题上困扰很久 这是我的解决思路: (1)检查网页(html/jsp)页面的编码: (2)检查服务器端的处理 ...
- java中文乱码解决之道(九)-----总结
乱码,我们前台展示的杀手,可能有些朋友和我的经历一样:遇到乱码先按照自己的经验来解决,如果没有解决就google,运气好一搜就可以解决,运气不好可能够你折腾一番了.LZ之所以写这个系列博客就是因为遇到 ...
随机推荐
- python之网络部分
1.C/S B/S架构 C: client端 B: browse 浏览器 S: server端 C/S架构: 基于客户端与服务端之间的通信 QQ, 游戏,皮皮虾, 快手,抖音. 优点: 个性化 ...
- chromedriver.exe下载
淘宝的镜像地址可以下载: https://npm.taobao.org/mirrors/chromedriver/
- 正则表达式、原始字符串及re
正则表达式.原始字符串及re re是python中的一个文本解析工具,常用的方法有: 来源:https://www.ibm.com/developerworks/cn/opensource/os-cn ...
- C++ 大数运算(加减乘除取模)
加法:(字符串模拟小学加法) string add(string s1, string s2) { int len1 = s1.length(), len2 = s2.length(); ; '); ...
- vi命令(待更新)
第一部分: 0:光标到本行行首$:光标到本行行尾 ^:本行第一个非blank的位置g_:本行最后一个非blank的位置 a:光标后插入(insert是光标前插入字符)o:当前行后加入新行O:当前行钱加 ...
- luogu P5371 [SNOI2019]纸牌
传送门 打麻将+1(雾 有顺子这种东西...注意到以某个位置为开头的顺子数量最多为2,那么有个想法就是枚举以每个位置为开头的顺子个数,然后每个位置的刻子的取法个数为\(\lceil\frac{\tex ...
- DNS 缓存投毒
原文:[DNS Cache Poisoning]( https://medium.com/iocscan/dns-cache-poisoning-bea939b5afaf) 译者:neal1991 w ...
- npm切换淘宝镜像源
npm 切换到淘宝源地址默认的npm下载地址:http://www.npmjs.org/淘宝npm镜像的地址:https://npm.taobao.org/ 临时使用淘宝源npm --registry ...
- C++质因数分解
// CPP.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include<cs ...
- 自己对GIS的思考
这只是我自己的理解,谈不上对整个行业的理解,只能从自己的角度谈谈GIS,谈谈爱和恨. 现在在武汉的一所所谓的全国GIS数一数二的学校里面读硕士,从高中开始我就很喜欢地理学科,大学选择了地球信息科技这个 ...