您的位置:首页 > 编程语言 > Java开发

解决SpringMvc框架中文乱码问题

2016-11-21 18:37 483 查看
1、检测web.xml配置是否ok

<filter>

    <description>字符集过滤器</description>

    <filter-name>encodingFilter</filter-name>

    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

    <init-param>

      <description>字符集编码</description>

      <param-name>encoding</param-name>

      <param-value>UTF-8</param-value>

    </init-param>

    <init-param>

       <param-name>enabled</param-name>

       <param-value>true</param-value>

   </init-param>

  </filter>

2、对Servlet的HttpServletResponse的属性进行设置

response.setCharacterEncoding("text/html,charset=utf-8");

3、requestMapping添加配置produces = {"application/json;charset=UTF-8"}

requestMapping(value = { "getPackageList"}, method = {RequestMethod.POST, RequestMethod.GET}

           ,produces = {"application/json;charset=UTF-8"})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: