关于SpringMVC乱码问题
2021-01-18 07:14
标签:匹配 span Servle rri java map back 表单 ram 关于SpringMVC运行Tomcat控制台出现乱码的情况(在网上找到一种方法亲测有效) 找到tomcat文件夹中的conf包下的logging.properties中找到 java.util.logging.ConsoleHandler.encoding = UTF-8 将这行代码注销改为 java.util.logging.ConsoleHandler.encoding = GBK 重启tomcat即可! 关于SpringMVC提交表单时,网页出现乱码情况,有两种解决方法 方法一(自定义过滤器): 在web.xml中配置过滤器 注意点: / 与 /* 的区别 / : 只匹配所有请求,不会去匹配jsp页面 /* : 匹配所有请求,包括jsp页面 关于SpringMVC乱码问题 标签:匹配 span Servle rri java map back 表单 ram 原文地址:https://www.cnblogs.com/peanutBlog/p/12913972.html 1 public class EncodingFilter implements Filter {
2 @Override
3 public void init(FilterConfig filterConfig) throws ServletException {
4
5 }
6
7 @Override
8 public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
9 servletRequest.setCharacterEncoding("utf-8");
10 servletResponse.setCharacterEncoding("utf-8");
11
12 filterChain.doFilter(servletRequest,servletResponse);
13 }
14
15 @Override
16 public void destroy() {
17
18 }
19 }
1 filter>
2 filter-name>encodingfilter-name>
3 filter-class>com.kuang.filter.EncodingFilterfilter-class>
4 filter>
5 filter-mapping>
6 filter-name>encodingfilter-name>
7 url-pattern>/*url-pattern>
8 filter-mapping>
方式二(SpringMVC自带的过滤器) 1 filter>
2 filter-name>characterEncodingFilterfilter-name>
3 filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
4 init-param>
5 param-name>encodingparam-name>
6 param-value>UTF-8param-value>
7 init-param>
8 filter>
9 filter-mapping>
10 filter-name>characterEncodingFilterfilter-name>
11 url-pattern>/*url-pattern>
12 filter-mapping>
上一篇:10.递归算法最佳解析
下一篇:1.认识java