SpringMVC乱码问题
SpringMVC乱码问题
1.我查看了jsp编码,设置了UTF-8
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%>
2.我查看了IDEA编码,也是UTF-8
3.我查看了传入controller里面的值是正常的,给前台返回的数据也是正常的,但是返回到前台显示就乱码。
解决方法:
在web.xml中配置:
<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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
配置结束,重新编译一下,启动测试
乱码问题解决。