spring get方法 中文(UTF-8)乱码
问题:
前端用Get方法进行如下请求:
在浏览器中输入:http://localhost:8080/dmaList/ExportBySQL?sql=&names=分区级别&size=10¤tpage=1
后端方法接收代码如下:
@RequestMapping(value="/ExportSQL",produces = "text/plain;charset=UTF-8")
@ResponseBody
public Boolean ExportMonitorStationInfoBySQL(HttpServletRequest request,HttpServletResponse response,@RequestParam(value="sql") String sql,@RequestParam(value="size") int size,@RequestParam(value="names") String names,@RequestParam(value="currentpage") int currentPage)
{
try {
names = new String(names.getBytes("ISO-8859-1"),"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int offset=(currentPage-1)*size;
int totalCount=dmaServcie.getDmaCountByAdvance(sql);
List<WLCS_DMAExt>data= dmaServcie.getDmaByPageByAdvance(sql, size, offset);
Page<WLCS_DMAExt> result=new Page<WLCS_DMAExt>(currentPage, size, totalCount, data);
return dmaServcie.ExportMonitorStationInfo(response, names, data);
}
结果参数names乱码,如下图所示。

解决办法:
使用names = new String(names.getBytes("ISO-8859-1"),"UTF-8");
上面的代码已经把解决办法写出来了,转换后的结果如下图所示:

PS:
项目中使用了如下方法(在web.xml中添加)解决乱码问题,结果不行:
<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>
<filter>
spring get方法 中文(UTF-8)乱码的更多相关文章
- 使用Spring PropertyPlaceholderConfigurer 配置中文出现乱码的解决方法
在使用org.springframework.beans.factory.config.PropertyPlaceholderConfigurer 读取配置文件时,发现对于中文的处理会出现乱码现象,比 ...
- Spring MVC Controller中解析GET方式的中文参数会乱码的问题(tomcat如何解码)
Spring MVC Controller中解析GET方式的中文参数会乱码的问题 问题描述 在工作上使用突然出现从get获取中文参数乱码(新装机器,tomcat重新下载和配置),查了半天终于找到解决办 ...
- Spring+MyBatis实践—中文乱码
多种中文乱码问题及解决: jsp页面乱码 表单提交乱码 URL中文参数乱码 1.jsp页面乱码解决(2步): 新建jsp页面: <%@ page language="java" ...
- 玩转web之ajax(一)---使用表单的serialize()方法中文乱码解决
有时候我们需要使用ajax提交去提交form的值,这样就需要使用serialize()去获取form的值,但这样获取的值如果有中文,会乱码,原因和解决方法如下: 原因:.serialize()自动调用 ...
- asp.net url址址中中文汉字参数传递乱码解决方法
中文乱码是网站开发中会常碰到的问题,今天我们来讲一下关于url址址中中文汉字参数传递乱码解决方法,有需要的朋友可以参考下.在cs文件里传参的时候用UrlEncode: Response.Redirec ...
- springmvc将处理后的数据通过get方法传给页面时,可能会出现乱码。下面对于get请求中文参数出现乱码提出解决办法。
对于get请求中文参数出现乱码解决办法有两个: 1.修改tomcat配置文件(tomcat--->conf--->server.xml)添加编码与工程编码一致,如下: <Connec ...
- JabRef中添加中文文献出现乱码 解决方法
JabRef中添加中文文献出现乱码 解决方法 问题描述 JaBRef是一款开源的文献管理软件,主要用来管理bibtex格式的参考文献,可以与LATEX配合使用,方便论文参考文献的使用.文献管理 ...
- Python3:读取配置dbconfig.ini(含有中文)显示乱码的解决方法
Python3:读取配置dbconfig.ini(含有中文)显示乱码的解决方法 一.原因 Python 3 中虽有encoding 参数,但是对于有BOM(如Windows下用记事本指定为utf-8) ...
- JSP HTML 各种 乱码 解决方法|jsp include html乱码|include 乱码|MyEclipse 中文乱码
笔者花了一整天研究这个问题 .最终解决了所有的中文乱码问题. 不用 写 过滤器,不用改 tomcat 的配置文件 笔者使用的 软件是 MyEclipse2013 professional 版 JSP ...
随机推荐
- hdu 4430 Yukari's Birthday (简单数学 + 二分)
Problem - 4430 题意是,给出蜡烛的数量,要求求出r和k,r是蜡烛的层数,k是每一层蜡烛数目的底数. 开始的时候,没有看清题目,其实中间的那根蜡烛是可放可不放的.假设放置中间的那根蜡烛,就 ...
- LEMP--如何在Ubuntu上安装Linux、Nginx、MySQL和PHP
简介 LEMP是用来搭建动态网站的一组软件,首字母缩写分别表示Linux.Nginx(Engine-X).MySQL和PHP. 本文将讲述如何在Ubuntu安装LEMP套件.当然,首先要安装Ubunt ...
- Activiti7工作流+SpringBoot
文章目录 一. Activiti相关概念 1. Activiti介绍 2. 核心类 2.1 ProcessEngine 2.2 服务(Service)类 2.2.1 TaskService 2.2.2 ...
- hadoop 端口总结
localhost:50030/jobtracker.jsp localhost:50060/tasktracker.jsp localhost:50070/dfshealth.jsp 1. Name ...
- H5 移动端获取当前位置
3种方法:1.H5自带的方法,获取经纬度2.通过地图提供的JS.获取位置3.通过微信的API(这个需要公众号 / 小程序) 1.通过H5自带的获取经纬度的方法 优点: 需要引用的资源较少,H5自带的方 ...
- 后缀数组 + LCP加速多模式匹配算法 O(m+logn)
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
- Layout 实现三栏布局的几种方法
https://github.com/ljianshu/Blog/issues/14 布局参考 https://github.com/ljianshu/Blog/issues/38 响应式那点 ...
- H3C 静态默认路由配置
- artDialog4.0.5
artDialog4.0.5 2011-08-22 11:54:36 haiwei_sun 阅读数 4109 收藏 更多 分类专栏: jquery 下载 Google Code 项目主页 最新版 ...
- tf.truncates_normal()
转载自:https://blog.csdn.net/uestc_c2_403/article/details/72235565 tf.truncated_normal(shape, mean, std ...