package com.diancai.interceptor; 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 javax.servlet.http.HttpServletResponse; import org.springframework.web.context.ContextLoaderListener; public class HeadFilter implements Filter{ @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest hreq = (HttpServletRequest) request; HttpServletResponse hres = (HttpServletResponse) response; hres.sendRedirect("index.jsp"); // 拦截的页面和跳转页面 是一个页面的时候可能出现死循环 // eclipse tomcat 启动 和 servers 启动不同:servers 在tomcat启动时自动执行filter.do,如果跳转页正好和拦截页一样,就 会出现 死循环,导致tomcat在启动完成后,仍然无法正常启动,启动超时、。 } @Override public void destroy() { } }
<!-- <filter-mapping>
<filter-name>head</filter-name>
<url-pattern>/index.jsp</url-pattern>
</filter-mapping> -->
<!-- <filter>
<filter-name>head</filter-name>
<filter-class>com.diancai.interceptor.HeadFilter</filter-class>
</filter> -->
// 拦截的页面和跳转页面 是一个页面的时候可能出现死循环
时间: 2024-10-04 16:41:57