1.在control的注解中声明
   
   
@RequestMapping(value="/httpclient/post", method=RequestMethod.POST,
produces=MediaType.TEXT_PLAIN_VALUE+";charset=utf-8")
2.在web.xml中配置如下
   
   
<!-- 解决post乱码 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3.返回值中进行设置
   
   
String studentId = new String(request.getParameter("studentId").getBytes("iso-8859-1"), "utf-8");
Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐