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之所以写这个系列博客就是因为遇到 ...
随机推荐
- 组合&多态&封装
目录 组合&多态&封装 一.组合 1.1什么是组合 1.2 为什么要用组合 1.3 如何使用组合 1.4 继承和组合都在什么时候用 二.多态与多态性 2.1 什么是多态 2.2 如何用 ...
- HNUSTOJ-1621 Picking Cabbage(状态压缩DP)
1621: Picking Cabbage 时间限制: 2 Sec 内存限制: 32 MB提交: 26 解决: 14[提交][状态][讨论版] 题目描述 Once, Doraemon and N ...
- PHP post调接口代码
PHP post调接口代码 /** * $url:接口地址 * $data:数组参数 **/ function postData($url, $data) { $ch = curl_init (); ...
- php转码 iconv和mb_convert_encoding
最近在给公司做一个小工具,将excel表格按照一定的格式转为txt文本格式,要求转后的txt文本是GBK编码,但是总会有几个excel表格无法正常转码,最后查阅相关资料,得到解决方案 先说明下,在ph ...
- HBASE学习笔记(三)
一. 1.预切割:在创建表的时候,预先对表进行region切割.切割线就是rowkey $hbase> create '] $hbase>create 'ns2:t3',SPLITS=&g ...
- 将div生成图片并下载下来
//文件需要引入html2canvas.js.jquery.js function downLoadImg(){ var element = $(".orgchart"); // ...
- 2019-11-29-C#-序列类为-xml-可以使用的特性大全
title author date CreateTime categories C# 序列类为 xml 可以使用的特性大全 lindexi 2019-11-29 8:59:2 +0800 2018-6 ...
- :OpenCV人脸识别Fisherface算法源码分析
https://blog.csdn.net/loveliuzz/article/details/73875904
- Laravel 向公共模板赋值
开发过程中许多时候都会向公共模板赋值,比如顶部导航栏,页面底部等等,不可能在每个控制器中都赋值一遍. Laravel 中解决办法如下:修改 App\Providers\AppServiceProvid ...
- [转]为什么要引入nullptr?
来源:https://cloud.tencent.com/developer/ask/69685 C++11介绍nullptr,它被称为Null指针常数及其提高类型安全性和解决不明确的情况与现有实现相 ...