1. 程式人生 > >IDEA專案執行頁面中文顯示亂碼解決方法

IDEA專案執行頁面中文顯示亂碼解決方法

一,在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>

二,在呼叫的方法後加上程式碼

produces = "text/plain;charset=utf-8"

三,修改tomcat/conf/server.xml檔案,在HTTP Connector或者AJP Connector的配置里加上URIEncoding="utf-8"