SpringMVC乱码 SpringMVC Tomcat控制台乱码问题解决方案
努力学习的Peanut 人气:0关于SpringMVC运行Tomcat控制台出现乱码的情况(在网上找到一种方法亲测有效)
找到tomcat文件夹中的conf包下的logging.properties中找到
java.util.logging.ConsoleHandler.encoding = UTF-8
将这行代码注销改为
java.util.logging.ConsoleHandler.encoding = GBK
重启tomcat即可!
关于SpringMVC提交表单时,网页出现乱码情况,有两种解决方法
方法一(自定义过滤器):
public class EncodingFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { servletRequest.setCharacterEncoding("utf-8"); 10 servletResponse.setCharacterEncoding("utf-8"); filterChain.doFilter(servletRequest,servletResponse); } @Override public void destroy() { } }
在web.xml中配置过滤器
<filter> <filter-name>encoding</filter-name> <filter-class>com.kuang.filter.EncodingFilter</filter-class> </filter> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
注意点: / 与 /* 的区别
/ : 只匹配所有请求,不会去匹配jsp页面
/* : 匹配所有请求,包括jsp页面
方式二(SpringMVC自带的过滤器)
1 <filter> 2 <filter-name>characterEncodingFilter</filter-name> 3 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 4 <init-param> 5 <param-name>encoding</param-name> 6 <param-value>UTF-8</param-value> 7 </init-param> 8 </filter> 9 <filter-mapping> 10 <filter-name>characterEncodingFilter</filter-name> 11 <url-pattern>/*</url-pattern> 12 </filter-mapping>
加载全部内容