springmvc返回数据中文乱码
今天用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;
}
調用該接口,返回數據中文未出現亂碼。
總結
以上是生活随笔為你收集整理的springmvc返回数据中文乱码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用springmvc作接口时返回json
- 下一篇: springmvc数据验证