springmvc返回数据中文乱码
2014-08-28 10:02
393 查看
今天用springmvc作为接口产生了中文乱码,因为返回的是string 就不能用以前的更改responseBody了 。
在spring-mvc.xml文件中:
<mvc:annotation-driven/>更改为
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
解决问题。
@RequestMapping(value="/getWorks.html" ,method=RequestMethod.POST)
public @ResponseBody String getWork(@RequestParam(value = "xml") String xml,HttpServletResponse response) throws UnsupportedEncodingException {
System.out.println("xml:"+xml);
ViewYyRecord record=null;
try {
record=RecordXmlUtil.getRecords(xml);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//WorkService workService=(WorkService) SpringContextUtil.getBean("workService");
String ret=workService.getWork(record);
System.out.println("最后结果"+ret);
return ret;
}
调用该接口,返回数据中文未出现乱码。
在spring-mvc.xml文件中:
<mvc:annotation-driven/>更改为
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
解决问题。
@RequestMapping(value="/getWorks.html" ,method=RequestMethod.POST)
public @ResponseBody String getWork(@RequestParam(value = "xml") String xml,HttpServletResponse response) throws UnsupportedEncodingException {
System.out.println("xml:"+xml);
ViewYyRecord record=null;
try {
record=RecordXmlUtil.getRecords(xml);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//WorkService workService=(WorkService) SpringContextUtil.getBean("workService");
String ret=workService.getWork(record);
System.out.println("最后结果"+ret);
return ret;
}
调用该接口,返回数据中文未出现乱码。
相关文章推荐
- springmvc ajax返回数据中文乱码
- 通过url地址获取数据后将数据利用SpringMVC的@ResponseBody返回中文可能出现乱码地方
- Java 简单解决springmvc获取properties文件里面中文内容出现论码问题(我遇到的问题是数据提交检验时返回的错误提示出现乱码)
- SpringMVC返回json数据+解决中文乱码
- springMVC返回json数据时,字符串中文乱码
- SpringMVC返回数据中文乱码问题浅析
- SpringMVC中ACTION返回JSON数据中文乱码
- springmvc接口返回xml数据出现中文乱码的问题
- 解决springmvc返回json数据IE出现文件下载和json数据中文乱码问题
- SpringMVC 返回JSON数据类型常常会中文乱码 之二
- 用springmvc作接口时返回json数据中文乱码
- servlet读取表单数据和返回页面时的中文乱码问题
- SpringMVC 3.1下返回json时中文显示乱码问题的解决方案
- SpringMVC中使用jackson,注解@ResponseBody返回中文乱码问题
- SpringMVC3.2 处理Ajax请求时返回json字符串的中文乱码问题
- Spring MVC 对于返回JSON格式数据的中文乱码 解决方法
- springMVC_json格式数据的接收和发送(未解决中文乱码问题)
- Ext返回json数据的中文为乱码
- springmvc 4.x 处理json 数据时中文乱码
- Spring MVC后台返回JSON数据中文乱码问题解决