<filter>
<filter-name>过滤器的名字</filter-name>
<filter-class>
过滤器的路径(servlet)
</filter-class>
<init—param>
<param—name>RejectedlP</param-name>//过滤器初始化参数名RejectedlP
<param-value>192.168.12.*/param-value>
</init—pamm>
</filter>
<filter-mapping>
<filter-name>必须和上面的过滤器名字一致</filter-name>
<url-patter>/course.htm</url-pattern><!-- 访问哪些页面或者跳转的文件 -->
</filter-mapping>
public class CourseCheckFilter implements Filter {
private Logger log=Logger.getLogger(this.getClass());
public void destroy() { }
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse res=(HttpServletResponse)response;
HttpServletRequest req=(HttpServletRequest)request;
if(req.getRequestURI().endsWith("course.htm")==false)//只对course.htm文件过滤
{
chain.doFilter(request,response);//通过不处理
return;
}
String requestURL=req.getRequestURL().toString();
String strParam=req.getQueryString();
if(strParam!=null&&strParam.length()>0)
{
requestURL=requestURL+"?"+strParam;
}
String SSO_URL="warn.htm?"+strParam
if(check(req,res)==false)
{
res.sendRedirect(SSO_URL);;//跳转到course.htm时不符合条件是跳转到该路径
return;
}
chain.doFilter(request,response); //通过不处理
}
}