摘要
最近没事儿瞎折腾java web,在idea中,突然发现无法显示页面了。
问题
为什么会出现这个问题?
接触了过滤器的内容,然后在项目中添加了这样的一个过滤器,用来对post过来的数据进行ut8编码。
packagecom.shop.filter;import javax.servlet.*;importjava.io.IOException;/*** post请求过滤器*/
public class EncodingFilter implementsFilter {
@Overridepublic void init(FilterConfig filterConfig) throwsServletException {
}
@Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain filterChain) throwsIOException, ServletException {
servletRequest.setCharacterEncoding("UTF-8");
}
@Overridepublic voiddestroy() {
}
}
注意,对过滤器的生命周期,是在服务器启动的时候,会对过滤器进行初始化,根据web.xml配置文件中的url-pattern进行过滤。
post-encoding
com.shop.filter.EncodingFilter
post-e