SSM框架:解决后台传数据到前台中文乱码问题,使用@ResponseBody返回json 中文乱码
2024-08-24 08:19:59
解决方法一:@RequestMapping(value="/getphone",produces = "text/plain;charset=utf-8")
/**输入手机号码后判断手机号是否存在*/
@RequestMapping(value="/getphone",produces = "text/plain;charset=utf-8")
@ResponseBody
public String getphone(String phone,HttpSession session){
Users u=service.selectPhoneService(phone);
if(u==null){//如果为空,则需要注册
String str="请您先注册,再登录。";
session.setAttribute("str", str);
return "请您先注册,再登录。";
}
return "true";
}
解决方法二,在spring-mvc.xml中添加:
<!-- 处理请求返回json字符串的中文乱码问题 -->
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
以上两种方式经过验证都没有问题。
最新文章
- Android ListView初始化简单分析
- SGU 142.Keyword
- 下拉框Html.DropDownList 和DropDownListFor 的经常用法
- Mysql操作个人收集
- poj 1456 Supermarket(并查集维护区间)
- 【转】Objective-C Runtime
- 编译虚拟机jvm——openjdk的编译
- mysql索引规范
- 熟悉常用的HDFS操作
- Google 浏览器好用插件推荐
- 详解HTTPS、TLS、SSL
- AI算法第三天【矩阵分析与应用】
- css组合选择器
- 在Android源码中查找Java代码中native函数对应的C++实现
- 关于网站中Logo部分的写法
- web.xml配置遇到的问题
- Ubuntu登录Windows Server 2008r2 密码总是错误与NLA验证
- My97DatePicker基本用法
- eclipse zg项目学习
- 使用Nmon_Analyzer excel 问题总结