从网上查到的结论:
根据servlet2.3规范filter执行是按照web.xml配置的filter-mapping先后顺序进行执行,所以上面的配置会导致遇见*.do的url请求,先进行SecurityFilter的过滤器处理,这时候没有做编码处理,已经是乱码,到下面的filter处理时已经时乱码,再做编码处理已经没有用处。解决办法:
//错误的顺序: <filter-mapping> <filter-name>SecurityFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CharacterEncoding</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CharacterEncoding</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> //正确的顺序: <filter-mapping> <filter-name>CharacterEncoding</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CharacterEncoding</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>SecurityFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping>