解决乱码问题
1、自己尝试解决,但是不能解决某些情况的乱码问题
package filter;
import javax.servlet.*;
import java.io.IOException;
public class EncodingFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
chain.doFilter(request,response);
}
}
<filter>
<filter-name>encoding</filter-name>
<filter-class>filter.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2、由于以上方式不能解决所有的乱码问题,所以采用以下SpringMVC提供的解决办法
<filter>
<filter-name>enconding</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>enconding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>