使用maven的tomcat插件时的乱码问题解决

版权声明:转载请注明原文链接 https://blog.csdn.net/weixin_42529699/article/details/87900181

1、get请求乱码

(1)首先保证项目的编码一致:

(2)然后在pom文件的tomcat插件配置中,加上编码字符集的设置即可

<!--tomcat插件-->
<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <configuration>
        <port>8080</port>
        <path>/</path>
        <uriEncoding>UTF-8</uriEncoding>
    </configuration>
</plugin>

 

2、post请求乱码

在web.xml文件中配置请求编码过滤器

<!--post请求乱码过滤器-->
<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>

 

3、控制台乱码

程序中用System.out.println输出中文的时候显示乱码:前台的中文显示和数据库的中文都正常,只有控制台中文乱码

在maven启动中添加以下VM Options参数就可以解决控制台中文乱码:-Dfile.encoding=GB2312

猜你喜欢

转载自blog.csdn.net/weixin_42529699/article/details/87900181