登陆中发现css页面不见了,变成了光秃秃的输入框问题
变成了这种光秃秃的状态;
这种状态一般是css文件被过滤器拦截了,
当时的过滤器代码
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import net.wanho.web.EncodingRequest; public class EncodingFilter implements Filter { private FilterConfig filterConfig = null; public void init(FilterConfig fConfig) throws ServletException { this.filterConfig = fConfig; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { String encoding = filterConfig.getInitParameter("charset"); // 处理post请求编码问题 request.setCharacterEncoding(encoding); // response.setCharacterEncoding(encoding); response.setContentType("text/html;charset=" + encoding); chain.doFilter(request, response); } public void destroy() { } }
这种情况就是一下子把css页面也过滤掉了,所以我们要再增加一个过滤页面;
import javax.servlet.*; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebFilter("*.css") public class CSSFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // response.setCharacterEncoding(encoding); response.setContentType("text/css;charset=utf-8");//注意这里text/css chain.doFilter(request, response); } @Override public void destroy() { } }
然后重启一下编辑器,清除浏览器缓存,再试一次