HTTP的GET请求中文乱码
来源:互联网 发布:网游之演技一流张知 编辑:程序博客网 时间:2024/05/22 15:11
今日写完Controller的代码后,自测发现,参数若是中文,接收到的值为乱码。
最初以为是Spring容器的问题,百度后基本有以下几种解决方法:
1.web.xml中配置 CharacterEncodingFilter
2.把接收的参数转码 name = new String("name".getBytes("ISO-8859-1"), "UTF-8");
3.在<\mvc:annotation-driven/>中添加
<mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <!-- StringHttpMessageConverter编码为UTF-8,防止乱码 --> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg value="UTF-8"/> </bean> </mvc:message-converters> <mvc:argument-resolvers>
4.在RequestMapping中添加produces属性
@RequestMapping(value="one", method=RequestMethod.GET, produces="text/html;charset=utf-8")
实际测试发现,只有第二种有效,说明当前项目配置是没问题的。然后想到可能是容器的问题,查看ng配置后发现为UTF-8编码。于是查看tomcat配置,发现tomcat未设置编码,即使用默认的ISO-8859-1编码,改为UTF-8后,问题解决。
<Connector port="8019" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/>
0 0
- HTTP的GET请求中文乱码
- HTTP中URL的get请求,中文参数乱码
- Http get请求 中文乱码问题
- Get请求中文乱码
- Get请求中文乱码
- get请求中文乱码
- get请求中文乱码
- Get中文请求乱码
- get请求中文乱码?
- GET请求的中文乱码处理
- 解决Get请求中文乱码的问题
- 由于get请求的中文参数乱码
- Java 获取Http Get请求中文参数乱码解决方案
- NodeMCU教程 http.get请求及上传中文乱码解决方案
- 安卓http-get请求中有中文乱码解决方法
- 解决了中文乱码的http的get和post请求demo
- Android http get请求里中文是乱码的解决(其中一种情况)
- http 请求中文乱码
- Future和FutureTask区别
- centos7下安装fastdfs
- 转场动画 学习
- 我的CentOS环境部署过程:从vmware安装到环境搭建
- qt 使用xlslib操作execl
- HTTP的GET请求中文乱码
- Linux编程中目录内容的读取(实现ls功能)
- iOS 真机 Could not launch "***"
- Spring的AOP支持 使用Annotation方式
- 正则表达式
- Windows编程C++之句柄
- spark的task调度器(FIFO先进先出调度算法)
- bugfree配置和使用
- Installshield 打包安装包心得