在web.xml中:web
添加一個過濾器(filter),註冊 org.springframework.web.filter.CharacterEncodingFilter。spring
<filter> <filter-name>setEncoding</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>setEncoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
默認編碼爲:ISO-8859-1app