关于SpringMVC乱码问题
关于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"); 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自带的过滤器)
<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>
相关推荐
JudeJoo 2020-08-21
meleto 2020-08-15
玫瑰小妖 2020-07-18
dlutbob 2020-07-04
zmysna 2020-07-04
小鱿鱼 2020-06-26
MicroBoy 2020-06-17
zhongliwen 2020-06-13
zhongliwen 2020-06-13
qingjiuquan 2020-06-07
牧场SZShepherd 2020-06-03
zhangdy0 2020-05-31
spring艳 2020-05-30
方志朋 2020-05-30
咻pur慢 2020-05-27
mxcsdn 2020-05-27
HappyHeng 2020-05-16
spring艳 2020-05-16