過(guò)濾器攔截路徑配置的代碼
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.annotation.WebFilter;
/**
?* Servlet Filter implementation class FilterDemo4
?*/
//@WebFilter("/index.jsp")??? //訪(fǎng)問(wèn)index.jsp頁(yè)面的時(shí)候需要經(jīng)過(guò)過(guò)濾器
//@WebFilter("/user/*")
//@WebFilter("*.jsp")? //訪(fǎng)問(wèn)后綴名為.jsp的時(shí)候,過(guò)濾器就會(huì)進(jìn)行攔截
@WebFilter("/*")
public class FilterDemo4 implements Filter {
??? /**
???? * Default constructor.
???? */
??? public FilterDemo4() {
??????? // TODO Auto-generated constructor stub
??? }
?? ?/**
?? ? * @see Filter#destroy()
?? ? */
?? ?public void destroy() {
?? ??? ?// TODO Auto-generated method stub
?? ?}
?? ?/**
?? ? * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
?? ? */
?? ?public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
?? ??? ?System.out.println("filterdemo4...");
?? ??? ?chain.doFilter(request, response);
?? ?}
?? ?/**
?? ? * @see Filter#init(FilterConfig)
?? ? */
?? ?public void init(FilterConfig fConfig) throws ServletException {
?? ??? ?// TODO Auto-generated method stub
?? ?}
}
標(biāo)簽: